The Heading object represents an HTML heading element: <h1> to <h6>.
We can access a heading element via document.getElementById()
:
var x = document.getElementById("myHeading");
Click the button to set the color of the h2 element to red.
<!DOCTYPE html> <html> <body> <h2 id="myHeading">This is a h2 element.</h2> <button onclick="myFunction()">Test</button> <script> function myFunction() {/*from ww w.j a v a 2s .co m*/ var x = document.getElementById("myHeading"); x.style.color = "red"; } </script> </body> </html>