I know of two ways to find all the elements in the page.
document.getElementsByTagName('*')
and document.all
Is there a better way or is one of these the best?
I'm making an element selector (mostly for practice) and I want to know the most reliable way to get all of the elements in the page, to test against the selector.
document.all
is an outdated proprietary method from Microsoft. Don't use it.
document.getElementsByTagName('*')
is the W3C standard method of finding all the elements ina document - and surely the fastest - and works in Internet Explorer as well.
P.S. As someone is bound to chime in and provide a jQuery answer to this question, there's how to select all elements in a page using jQuery: jQuery('*');
:-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With