DEV Community

Himanshu Gupta
Himanshu Gupta

Posted on

2

What is the Difference Between children and childNodes?

What’s the difference between the ParentNode.children and Node.childNodes properties of an element?



var elem = document.querySelector('#my-element');
elem.children;
elem.childNodes;

Enter fullscreen mode Exit fullscreen mode




children

-> each element has that property,
-> is provided by Element class (that class implements Node interface),
-> contains only child elements (it has HTMLCollection type).
Hint: elements are:

, , , , , , etc.

childNodes

-> each node and each element have that property,
-> is provided by Node interface,
-> contains all child nodes (it has NodeList type),
Hint: nodes are: elements, texts and comments.

Image description

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more