Answers for "getelementsbyclassname and set innerhtml"

1

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");  // Find the elements
    for(var i = 0; i < x.length; i++){
    x[i].innerText="Hello JavaScript!";    // Change the content
    }

}

</script>
</body>
Posted by: Guest on March-25-2020

Code answers related to "getelementsbyclassname and set innerhtml"

Code answers related to "Javascript"

Browse Popular Code Answers by Language