HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
Through the HTML DOM, you are able to use the node in the node navigation tree relationship.
getElementsByTagName () method returns a list of nodes. Node list is a node array.
The following code selected document all <p> node:
It can be accessed by the next label. To access the second <p>, you can write:
note:
Under the label starts at 0.
length attribute defines the number of nodes in the node list.
You can use the length property to loop node list:
You can use three node attributes: parentNode, firstChild and lastChild, navigate through the document structure.
Consider the following HTML fragment:
firstChild property can be used to access elements of the text:
There are two special attributes, you can access all of the documentation:
In addition to innerHTML property, you can also use the childNodes and nodeValue property to get the content of the element.
The following code gets the id = "intro" the <p> element values:
In the example above, getElementById is a method, while childNodes and nodeValue are properties.
In this tutorial, we will use the innerHTML property. However, the above learning method helps to navigate the DOM tree structure and understanding.