What is the difference between the three samples below and which one is better (if any)?
$("#x span").hide();
$("#x").find("span").hide();
$("span", "#x").hide();
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.
They will all match the same thing; the best one is based on context. I would use the first example unless I had a variable pointing to an existing set. Then I would obviously use the
find()method on it.The old
$(selector, context)(your third example) isn’t seen much these days, probably because it translates to$(context).find(selector)behind the scenes anyway (and its easier to read that way).