javascript change text by class name code example
Example 1: javascript change color for class name
function reset() {
var elements = document.getElementsByClassName('pixel');
for(var i = 0; i < elements.length; i++){
elements[i].style.backgroundColor = "white";
}
}
Example 2: js document.getelementsbyclassname modify innertext
<body>
<p class="demo">JavaScript can change the content of an HTML element.</p>
<p class="demo">Yolo</p>
<button type="button" onclick="myFunction()">Click Me!</button>
<script>
function myFunction()
{
x=document.getElementsByClassName("demo");
for(var i = 0; i < x.length; i++){
x[i].innerText="Hello JavaScript!";
}
}
</script>
</body>