Get Header Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Header

Introduction

The Header object represents an HTML <header> element.

You can access a <header> element by using getElementById():

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<article>
  <header id="myHeader">
    <h3>header</h3>
  </header>
  <p>This is a test. This is a test. This is a test.</p>
</article>//from  w ww. j a v a  2s.c  o m

<button onclick="myFunction()">set the color of the header element to red</button>

<script>
function myFunction() {
    var x = document.getElementById("myHeader");
    x.style.color = "red";
}
</script>

</body>
</html>

Related Tutorials