.getElementById();

To access a unique element theĀ .getElementById(); method should be used.

 

var myElement = document.getElementById("myId"); //assigns a handle to the node containing id="myId"

 

 

This example assigns the element with an id of myHeading to a variable (handle) and then displays the text (using innerHTML) within that element:

Save & refresh browser:

An h1 tag element with an id of myHeading

An h1 tag element with an id of myHeading

Leave a Reply