Finding HTML Element by Id 1

Finding HTML Element by Id

var myElement = document.getElementById("intro");

Here is what the above code is Doing:
1. We’re creating a variable called myElement and setting it equal to the result of calling document.getElementById(), passing it “intro” as an argument.
2. The document.getElementById() method is a built-in JavaScript method for selecting an element by its id.
3. The argument we pass to document.getElementById() is the id of the element we want to select.
4. The result of calling document.getElementById() is an HTML element object.
5. We can store this HTML element object in a variable for later use.

Similar Posts