Create a Heading Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Heading

Introduction

You can create a heading element by using the document.createElement() method:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">create a H1 element with some text</button>

<script>
function myFunction() {//from   ww w .  ja  va2  s.  co m
    var x = document.createElement("H1");
    var t = document.createTextNode("Welcome");
    x.appendChild(t);
    document.body.appendChild(x);
}
</script>

</body>
</html>

Related Tutorials