Change the HTML content of the first <p> element (index 0) in the document:
document.getElementsByTagName("P")[0].innerHTML = "Hello World!";
Click the button to change the text of this paragraph.
<!DOCTYPE html> <html> <body> <p>This is also a paragraph.</p> <button onclick="myFunction()">Test</button> <script> function myFunction() {/*from www.j av a 2s .c o m*/ document.getElementsByTagName("P")[0].innerHTML = "Hello World!"; } </script> </body> </html>