The difference between children and childnodes

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.