Which is better to use as a performance perspective:
$(".div1 h2, .div1 h3")
or
$(".div1").find("h2, h3")
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.
The answer to your question is: yes.
Don’t worry about the performance difference, unless your code is slow. If it is, use a profiler to determine bottlenecks.
From an analysis standpoint:
should be faster as jQuery will pipe it through
querySelectorAll(if it exists) and native code will run faster than non-native code. It will also save on an additional function call.is better if you plan on chaining some other functions on
.div1: