Javascript Reference - HTML DOM Article Object








The Article class represents an HTML <article> element.

Article Object

The following code accesses an <article> element by using getElementById().


<!DOCTYPE html>
<html>
<body>
<article id="myArticle">
  <h1>Heading</h1>
  <p>this is a test.</p>
</article><!-- ww w  .  j av a 2  s.c o m-->
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
    var x = document.getElementById("myArticle");
    x.style.color = "blue";
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

The following code creates an <article> element by using the document.createElement() method:


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!-- ww w  . j  a va  2  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");
    heading.appendChild(txt1);
    document.getElementById("myArticle").appendChild(heading);
}
</script>

</body>
</html>

The code above is rendered as follows:





Standard Properties and Events

The Article object supports the standard properties and events.