Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
164
rated 0 times [  170] [ 6]  / answers: 1 / hits: 136092  / 12 Years ago, wed, october 10, 2012, 12:00:00

I'm trying to get all the elements (tags) inside the Body tag of an HTML page in an array using pure javascript. I mean without using any framework (ex. JQuery).


I've found that you can use document.all but that will return all the elements inside the whole document including the scripts.


Is there anyway I can get those tags?


More From » html

 Answers
131

If you want all elements inside the body tag, not just first level children, you can simply use getElementsByTagName() with a wildcard:



var elems = document.body.getElementsByTagName(*);

[#82629] Tuesday, October 9, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
johnniejarend

Total Points: 84
Total Questions: 91
Total Answers: 91

Location: British Indian Ocean Territory
Member since Tue, Feb 22, 2022
2 Years ago
;