Create an Article Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Article

Introduction

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">create an ARTICLE element containing a H1</button>

<script>
function myFunction() {//  w w w.  j av a2  s. c o  m
    var x = document.createElement("ARTICLE");
    x.setAttribute("id", "myArticle");
    document.body.appendChild(x);

    var heading = document.createElement("H1");
    var txt1 = document.createTextNode("Heading in Article");
    heading.appendChild(txt1);
    document.getElementById("myArticle").appendChild(heading);

}
</script>

</body>
</html>

Related Tutorials