开发者

DOM node child collections--what's the difference?

开发者 https://www.devze.com 2022-12-19 22:49 出处:网络
What\'s the difference between the children and childNodes collections of a node? And childElemen开发者_C百科tCount and childNodes.length?element.childNodes and element.childNodes.length: includes chi

What's the difference between the children and childNodes collections of a node? And childElemen开发者_C百科tCount and childNodes.length?


element.childNodes and element.childNodes.length: includes child elements, text nodes (including whitespace nodes between elements) and comments (plus potentially CDATASections, ProcessingInstructions, DocumentTypes and EntityReferences, depending on the document and parser). Defined by the DOM Level 1 Core standard and has been available on every browser for many years.

element.children and element.childElementCount: includes only element nodes, so can be simpler to handle in some cases. childElementCount is defined by the Element Traversal API standard and is available in the latest versions of Mozilla, Opera and WebKit. children is not defined by any standard, but is available in IE and up-to-date versions of Mozilla, Opera, WebKit and IE.


Children contains only elements. ChildNodes contains all nodes.

0

精彩评论

暂无评论...
验证码 换一张
取 消