xxleyi / learning_list

聚集自己的学习笔记
10 stars 3 forks source link

HTML children vs childNodes #225

Open xxleyi opened 4 years ago

xxleyi commented 4 years ago

The main difference between children and childNodes property is that children work upon elements and childNodes on nodes including non-element nodes like text and comment nodes.

One is element, the other is node.

get name:

element vs node:

一篇超棒的回答:javascript - Difference between Node object and Element object? - Stack Overflow

Constant Value Description
Node.ELEMENT_NODE 1 An Element node like <p> or <div>.
Node.TEXT_NODE 3 The actual Text inside an Element or Attr.
Node.CDATA_SECTION_NODE 4 A CDATASection, such as <!CDATA[[ … ]]>.
Node.PROCESSING_INSTRUCTION_NODE 7 A ProcessingInstruction of an XML document, such as <?xml-stylesheet … ?>.
Node.COMMENT_NODE 8 A Comment node, such as .
Node.DOCUMENT_NODE 9 A Document node.
Node.DOCUMENT_TYPE_NODE 10 A DocumentType node, such as <!DOCTYPE html>.
Node.DOCUMENT_FRAGMENT_NODE 11 A DocumentFragment node.