1.childNodes, gets the child node, itself is an array, you can use subscript childnodes[i] to get a sub-node.
alert (obj.childNodes.length); The presence of a blank node in an advanced browser
// the loop determines whether the element node is based on the NodeType type of the node
for (var i = 0, len = aElement.childNodes.length; i < Len; i++) { if(aelement.childnodes[i].node Type = =1 = "Red"; }}
2. Child nodes
Firstchild,firstelementchild;
Lastchild,lastelementchild;
3. Sibling nodes
previoussibling,previouselementsibling;
nextsibling,nextelementsibling;
// use if to Judge FirstChild and Firstelementchild to be compatible if = "Red";} Else = "Red";}
Other nodes in the same vein
// Remove white space nodes to be compatible with FirstChild function Cleanwhitespace (Element) { for (var i = 0; i < element.chiledNodes.length; i++) {var node = element.childnodes[i]; // loops the current child node if (Node.nodetype = = 3 &&!/\s/. Test (Node.nodevalue)) {node.parentNode.removeChild (); //\s matches any visible character when the node is a text node with Yes! /\s/, non-visible characters, delete these nodes }}
4. Parent element ParentNode
// Click the current a tab to find the parent of the a tag, and then hide var arrA = document.getElementsByTagName ("a"); for (var i = 0, len = arra.length; i < len; i++function() { th is. ParentNode.style.display = "None" }}
5. Selecting Elements with classname
// Choose Li with class as box to color it var aLi = document.getElementsByTagName ("li"); for (var i = 0, len = ali.length; i < Len; i++) { if(ali[i].classname = = "box") {
this. Style.background = "Red"
; }}
//PackagefunctionGetbyclass (objparent,targetclass) {varAresult = []; varAelement =objparent.getelementsbytagname ("*"); for(vari = 0, len = aelement.length; i < Len; i++) {if(Aelement[i].classname = =Targetclass) {Aresult.push (aelement[i]); }}returnAresult; Returns the array with the box as class}//call var Abox = Getbyclass (Anav, "box"); Get an array of class as Box for(vari = 0, len = abox.length; i < Len; i++) {Abox[i].style.background= "Red";}
2015.7.12JS-11 (Dom Foundation)