Om3ga
Om3ga

Reputation: 32951

Get all child elements including body using javascript

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

Answers (1)

Pranav C Balan
Pranav C Balan

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

Related Questions