I’m not a jQuery expert(not even a good user), i haven’t studied the whole source code of it (only a little part which can’t help me solve this problem).
Can somebody explain this for me?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This:
…uses the native
querySelectorAll.This:
…uses the native
getElementsByTagName.The
getElementsByTagNameis simply faster, perhaps because it is a very simple selection, and has been around longer, giving it more time for optimization.Also, when jQuery uses
querySelectorAll, it does so from thedocumenteven if you’re searching from a specified context, so this has an impact. To narrow the results to the context you provided, it changes your selector to use the ID of the element, or gives it a temporary one if non exists.I updated your test to give a few more comparisons. Shows that if you’re really concerned about performance, you should use the native API.