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

Javascript examples for DOM HTML Element:Heading


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>

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

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

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


Related Tutorials