Get Heading <h1> to <h6> - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Heading

Introduction

The Heading object represents an HTML heading element: <h1> to <h6>.

You can access a heading element by using getElementById():

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<h2 id="myHeading">This is a h2 element.</h2>

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

<script>
function myFunction() {/*from w  w  w  .  ja  v a  2 s . c  o m*/
    var x = document.getElementById("myHeading");
    x.style.color = "red";
}
</script>

</body>
</html>

Related Tutorials