DOM Access Node Nodes instance Tutorial
Here you can access each node of the HTML file.
Access node
You can use a node in three aspects:
1. By using the getElementById () method
2. By using the getElementsByTagName () method
3. Through the nodes of the navigation tree, the relationship between nodes is utilized.
The getElementById () method
The getElementById () method returns the element with the specified number:
Grammar
document.getElementById ("Someid");
Note: the getElementById () method does not work with XML.
All content returned by the getElementsByTagName () method getElementsByTagName () and the specified tag name.
Grammar
document.getElementsByTagName ("P");
Now let's take a look at example two.
document.getElementById (' main '). getElementsByTagName ("P");
List of DOM nodes the getElementsByTagName () method returns a list of nodes.
A list of nodes is a series of nodes.
The following code store's list <p> node (node list) in the variable x:
X=document.getelementsbytagname ("P"); elements of <p> in X can be numbered by index
。 Enter second <p> you can write: y=x[1];