javascriptchild-nodes

Why when childNodes is used, text and comment reutrns?


When i use childnode it also return, text and column and then it starts the element. Can some explain why it does that?


Solution

  • Per the MDN docs (emphasis mine):

    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.