How to find all the items on the page

I know two ways to find all the elements on a page.

document.getElementsByTagName('*') and document.all

Is there a better way or one of the best?

I am making an element selector (mainly for practice), and I want to know the most reliable way to get all the elements on a page to test the selector.

+4
source share
1 answer

document.all is an obsolete proprietary method from Microsoft. Do not use it.

document.getElementsByTagName('*') is the standard W3C method for finding all the elements in a document - and, of course, the fastest - and it works in Internet Explorer.

PS . When someone is required to call back and provide a jQuery answer to this question, how to select all the elements on the page using jQuery: jQuery('*');

:-)

+14
source

Source: https://habr.com/ru/post/1344207/


All Articles