为什么使用childNodes时返回的是text和comment?
Why when childNodes is used, text and comment reutrns?
当我使用子节点时,它还会 return、文本和列,然后启动元素。
有人可以解释为什么这样做吗?
根据 MDN docs(强调我的):
It is important to keep in mind that childNodes
includes all child nodes, including non-element nodes like text and comment. To get a collection containing only elements, use Element.children
instead.
当我使用子节点时,它还会 return、文本和列,然后启动元素。 有人可以解释为什么这样做吗?
根据 MDN docs(强调我的):
It is important to keep in mind that
childNodes
includes all child nodes, including non-element nodes like text and comment. To get a collection containing only elements, useElement.children
instead.