Document body Property - Create a <p> element with some text and append it to the document's body: - Javascript DOM

Javascript examples for DOM:Document body

Description

Document body Property - Create a <p> element with some text and append it to the document's body:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

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

<script>
function myFunction() {//  w w  w.  j  ava 2  s .c o m
    var x = document.createElement("P");
    var t = document.createTextNode("This is a paragraph.");
    x.appendChild(t);
    document.body.appendChild(x);
}
</script>

</body>
</html>

Related Tutorials