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.allis 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('*');🙂