Reputation: 32951
The code below gets all children within body
but it does not get the body
element itself. How can I get all child elements including body
with pure JavaScipt?
document.querySelectorAll('body *');
Upvotes: 3
Views: 1628
Reputation: 115282
You are getting all inner elements of body
tag instead use *
to get all elements.
document.querySelectorAll('*');
If you want to get body
and its all inner elements then use comma separated multiple selectors.
document.querySelectorAll('body,body *');
Upvotes: 4