2619 2619 - 1 year ago 156
Javascript Question

Get all child elements including body using javascript

The code below gets all children within

but it does not get the
element itself. How can I get all child elements including
with pure JavaScipt?

document.querySelectorAll('body *');

Answer Source

You are getting all inner elements of body tag instead use * to get all elements.


If you want to get body and its all inner elements then use comma separated multiple selectors.

document.querySelectorAll('body,body *');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download