Efficiency of selecting elements with `Document.querySelectorAll()` with class name when tag is optional

Viewed 28

Sorry if there is a similar/duplicate question on this forum, but I couldn't find a similar question asked here, please let me know if this is a duplicate.


In JavaScript, if I would like to find all nodes with class name classNameExample, I can use document.querySelectorAll('.classNameExample'). If given that all nodes with this specific class name have tag span, is document.querySelectorAll('.classNameExample') faster or document.querySelectorAll('span.classNameExample') faster?

I've thought about constructing an example and benchmarking it, but as a beginner I believe that also depends on the structure of the website, so it would be nice how it actually works and reasons behind. Thanks

0 Answers
Related