Accessing the HTML DOM - Finding HTML elements
Accessing an HTML element is the same as accessing a Node.
You can access an HTML element in different ways:
The getElementById() method returns the element with the specified ID:
The following example gets the element with id="intro":
getElementsByTagName() returns all elements with a specified tag name.
The following example returns a list of all <p> elements in the document:
The following example returns a list of all <p> elements that are descendants (children, grand-children, etc.) of the element with id="main":
If you want to find all HTML elements with the same class name. Use this
method:
The example above returns a list of all elements with class="intro".
NOTE: getElementsByClassName() does not work in Internet Explorer 5,6,7, and 8.
Your message has been sent to W3Schools.