Create a Header Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Header

Introduction

You can create a <header> element by using the document.createElement() method:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

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

<script>
function myFunction() {/*from   w  w  w . j av a  2 s  .  c o m*/
    var x = document.createElement("HEADER");
    x.setAttribute("id", "myHeader");
    document.body.appendChild(x);

    var y = document.createElement("H3");
    var t = document.createTextNode("This is a h3 element in a header element");
    y.appendChild(t);

    document.getElementById("myHeader").appendChild(y);
}
</script>

</body>
</html>

Related Tutorials