Document createElement() Method - Create a <p> element with some text, and append it to the document: - Javascript DOM

Javascript examples for DOM:Document createElement

Description

Document createElement() Method - Create a <p> element with some text, and append it to the document:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

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

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

</body>
</html>

Related Tutorials