The acquired DOM node element IE6-8 package compatible with source code analysis children jquery

<ul id="box">
<Li> first node </ li>
<Li> second node </ li>
<Li> third node </ li>
<Li> fourth node </ li>
</ul>
var box = document.getElementById('box');
// standard browser (non IE6-8) would spaces and line breaks in the text as a node processing
console.log(box.childNodes); //NodeList(9) [text, li, text, li, text, li, text, li, text]
// If you want an element node, but the use of children under IE6-8 comments will also be used as an element node
console.log(box.children);
// Get the children to specify the context of all of the elements of the child node compatible with all browsers IE6 +
function children(context){
var res = [],nodeList = context.childNodes;
for(var i = 0;i<nodeList.length;i++){
var item = nodeList[i];
item.nodeType === 1 ? res.push(item):null;
}
return item;
}
console.log(children(box).length);
 

Guess you like

Origin www.cnblogs.com/itsmart/p/12589328.html