Is there any benefit (performance or otherwise) for me to use the .eq(0) filter when I reference the body tag in a jQuery object? For instance: $(“body”).eq(0) as opposed to just $(“body”).
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.
No
$("body")should do just fine..eq(0)is just to pick the first element and it won’t make any difference if it has just one element to begin with.$('body')will have the same structure as$('body').eq(0)but.eqis just an extra call..eqfunction implementationAs you see, it doesn’t make sense to do a
eqwhen you just have only one element.