It all comes down to what methods in the DOM engine Sizzle (which jQuery uses to evaluate selectors) can use to search for elements.
It can use the getElementById and getElementsByTagName methods to quickly get items for a specific identifier and for a specific tag name. After that, he just needs to go through all the elements found and compare them with the conditions created from the selector.
Methods in the DOM can be used for any element and used in combination, so, for example, finding all div elements inside an element with a specific identifier is very fast.
Guffa source share