1.
For example:
<title> node Tree <title/>
<body>
<p> Student Information <p/>
<ul id = "UL1" >
<li> name <li/>
<li id= "Sex" > Sex <li/>
<li> Age <li/>
<ul/>
<body/>
The child nodes of HTML are body and head while body and head are two sibling nodes, and the parent node is HTML. The child node of head is the title.
2. Accessing the specified element (method)
getElementById (); Note: Gets the element with the specified ID and returns an object. Getelementsbyname (); Note: Gets the element with the specified name, and returns a collection. Geteilementsbytagname (); Note: The element that gets the specified label returns a collection. Getelementsbyclassname (); Note: Gets the element of the specified class and returns a collection.
For example:
Get the LI tag with the ID of sex:
var v = document.getElementById ("Sex");
Get all the LI tags
var v = document.geteliementsbytagname ("Li");
3. Accessing the specified element (attribute)
parentnode; Note: Gets the parent tag of the element, returning an object because each tag has only one parent tag. Chidnodes; Note: Gets the child tag of the specified element, the space is also a child tag, and returns a collection. FirstChild; Note: Gets the first child node and returns an object. LastChild; Note: Gets the last child node that returns an object. previoussibling; Note: Gets the previous sibling node and returns an object. nextSibling; note: After a sibling node is obtained, an object is returned.
For example:
Get Li's parent tag ul
var v = document.getElementById ("Sex"). parentnode;
Get UL's sub Mark Li
var v = document.getElementById ("Ul1"). ChildNodes;
JavaScript DOM node tree