1:childnodes/Children the same point: it returns a collection of child elements of the specified element.
2: Difference: Children : It is non-standard and returns only HTML nodes. Does not even return a text node. All browsers behave consistently.
ChildNodes: It is standard and returns all attributes, including HTML nodes, text. NodeType can be used to determine what type of node, when Nodetype==1 is an element node, 2 is an attribute node, and 3 is a text node.
JS Operation document, try to use childnodes to get div node div child node, IE browser does not have any problems,
The FF browser will also count the nodes of the Text_node type into the child nodes, which will operate to the wrong object. You can add if (obj.nodetype==3) {continue;} in the loop. Else{do something ...} To be compatible.
Some people mistakenly use () to fetch the collection element, and the following table lists the supported scenarios for ChildNodes (i) for each browser:
|
Ie6/7/8/safari/chrome/opera |
Ie9/firefox |
ChildNodes (i) |
Support |
Not supported
|
The difference between children and childnodes