Javascript Reference - HTML DOM Header Object








The Header object represents an HTML <header> element.

Standard Properties and Events

The Header object supports the standard properties and events.

Example

The following code shows how to get a <header> element by using getElementById()


<!DOCTYPE html>
<html>
<body>
<article>
  <header id="myHeader">
    <h3>head 3</h3>
  </header>
  <p>text</p>
</article><!--  ww w.  j  a  v a 2 s  .c  om-->
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
    var x = document.getElementById("myHeader");
    x.style.color = "red";
}
</script>
</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to create a <header> element by using the document.createElement() method


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!--from w w  w  .  ja va 2  s .  c  om-->
    var x = document.createElement("HEADER");
    x.setAttribute("id", "myHeader");
    document.body.appendChild(x);
    var y = document.createElement("H3"); 
    var t = document.createTextNode("header");
    y.appendChild(t);

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

The code above is rendered as follows: