May 09, 2021 HTML DOM
Access HTML DOM - Find HTML elements.
Accessing HTML elements is equivalent to accessing nodes
You can access HTML elements in different ways, such as:
The getElementById() method returns an element with a specified ID:
Here's an example to get an element of id"intro" and click "Try it" to edit it:
GetElementsByTagName() returns all elements with the specified label name.
The following example returns a list of all the elements in the document and clicks "Try it" to edit it:
The following example returns a list of all the elements in the document, and the elements should be descendants (children, grandchildren, etc.) of the elements of the id"main", and click "Try it" to edit:
If you want to find all HTML elements with the same class name, you can use this method to find:
The example above returns a list of all the elements that contain class"intro":
Note: GetElementsByClassName() is not valid in Internet Explorer 5,6,7,8.