Change the text of an element with id="demo":
document.querySelector("#demo").innerHTML = "Hello World!";
Click the button to change the text of the p element.
<!DOCTYPE html> <html> <body> <p id="demo">This is a p element with id="demo".</p> <button onclick="myFunction()">Test</button> <script> function myFunction() {//from www. j a va2 s . c o m document.querySelector("#demo").innerHTML = "Hello World!"; } </script> </body> </html>