Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all child elements including body using javascript

Tags:

javascript

dom

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 *');
like image 223
Om3ga Avatar asked Jun 13 '26 09:06

Om3ga


1 Answers

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 *');
like image 85
Pranav C Balan Avatar answered Jun 16 '26 08:06

Pranav C Balan