The difference _javascript skills between childnodes.length and Children.length

Source: Internet
Author: User
BecausechildnodesContains more than justHTMLNodeAllProperty,Text, etc. are included in thechildnodesInside,You can passNodeTypeTo determine what type of node it is, only whennodetype==1To make the element node,2is the attribute node,3is a text node. and Children.length only the number of nodes is counted.
This includes the calculation of the node length, which should be noted when the node is moved.
To get the text of an element, such as to get aPThe text of the node, some people like to useInnerHTML, the change is the same, in fact this is not very good, because the use ofInnerHTMLThe browser will think that what you are inserting is a piece of label text, and you just want to insert a piece of plain text, which causes the browser to try to parse your plain text, which can cause unnecessary waste of resources. So it is recommended to useElement.firstChild.nodeValue,Why isFirstChildIt? BecauseChildnodes[0]is the text node, you can look at it without believing it.NodeType
Related Article

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.