js document getelementsbyclassname modify innertext

Solutions on MaxInterview for js document getelementsbyclassname modify innertext by the best coders in the world

showing results for - "js document getelementsbyclassname modify innertext"
Jana
21 May 2018
1<body>
2
3<p class="demo">JavaScript can change the content of an HTML element.</p>    
4<p class="demo">Yolo</p>   
5
6<button type="button" onclick="myFunction()">Click Me!</button>
7
8<script>        
9function myFunction()
10{
11x=document.getElementsByClassName("demo");  // Find the elements
12    for(var i = 0; i < x.length; i++){
13    x[i].innerText="Hello JavaScript!";    // Change the content
14    }
15
16}
17
18</script>
19</body>