Looking into selector performance between $(‘#ID1, #ID2, #ID3’) vs $(‘1X CLASS’). Which is faster?
Looking into selector performance between $(‘#ID1, #ID2, #ID3’) vs $(‘1X CLASS’). Which is faster?
Share
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.
Looks like
.classis working faster for this case. jQuery might not be going thegetElementByIdroute. Chrome and Safari are probably being optimizing withgetElementsByClassName.Tests @ http://jsfiddle.net/mGqyH/4/
Chrome
Chrome http://img339.imageshack.us/img339/5021/chromew.png
Safari
alt text http://img339.imageshack.us/img339/5021/chromew.png
Firefox
Firefox performance http://img94.imageshack.us/img94/1123/firefoxg.png
Document used (modified)
combined IDs selector
disjoint IDs selector
class selector