HTML DOM access
Access to HTML DOM - find HTML elements.
Access HTML elements (nodes)
Access HTML elements equivalent to Access Node
You can be in a different way to access HTML elements:
- By using the getElementById () method
- By using the getElementsByTagName () method
- By using getElementsByClassName () method
getElementById () method
getElementById () method returns the element with the specified ID:
grammar
The following example Get id = "intro" element:
Examples
getElementsByTagName () method
getElementsByTagName () returns all elements with the specified tag name.
grammar
The following example returns a list of documents that contain all the <p> element:
Example 1
The following example returns a list of documents that contain all the <p> element, and the <p> element should be a descendant id = "main" element (child, Sun, etc.):
Example 2
The getElementsByClassName () Method
If you want to find all HTML elements with the same class name, use this method:
Returns a list containing the above example class = "intro" all the elements:
Note: getElementsByClassName () is not valid in 5,6,7,8 in Internet Explorer.