Document getElementsByTagName() Method - Change the HTML content of the first <p> element (index 0) in the document: - Javascript DOM

Javascript examples for DOM:Document getElementsByTagName

Description

Document getElementsByTagName() Method - Change the HTML content of the first <p> element (index 0) in the document:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p>This is also a paragraph.</p>

<button onclick="myFunction()">Test</button>

<script>
function myFunction() {//from  w w  w . jav a 2 s. co  m
    document.getElementsByTagName("P")[0].innerHTML = "Hello World!";
}
</script>

</body>
</html>

Related Tutorials