Document createTextNode() Method - Create a <h1> element with some text: - Javascript DOM

Javascript examples for DOM:Document createTextNode

Description

Document createTextNode() Method - Create a <h1> element with some text:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

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

<script>
function myFunction() {/*w  w w .j a v  a  2s  .c o  m*/
    var h = document.createElement("H1");
    var t = document.createTextNode("Hello World");
    h.appendChild(t);
    document.body.appendChild(h);
}
</script>

</body>
</html>

Related Tutorials