BecauseChildNodesNot onlyHtmlNode, AllAttribute,TextAre included inChildNodesInside,You can useNodeTypeTo determine the type of node, only whenNodeType = 1Make the element node,2Yesattribute node,3Is a text node. WhileChildren. lengthOnly count the number of nodes.
This includes calculating the node length. Pay attention to this when moving nodes.
To obtain the text of an element, for example, to obtainPNode text, which is preferred by someInnerHTMLAnd the change is the same. In fact, this is not very good because of the useInnerHTMLThe browser will think that what you want to insert is a piece of label text, and you just want to insert a piece of plain text, which leads the browser to try to parse your plain text, this will cause unnecessary waste of resources. Therefore, we recommend that you useElement. firstChild. nodeValue,Why?FirstChildWhat about it? BecauseChildNodes [0]It's a text node. You can check it if you don't believe it.NodeType.