var $this = $(this);
Given the above, which is faster: $(".elt", $this) or $this.find(".elt")?
I ask because the first seems a bit more concise, but if it converts to $($this).find(".elt") [sic], it seems that it could in fact be slower.
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.
It is much faster to use
$("#elt")since there is only one element with anid="elt"that is a valid element. (ID’s MUST BE UNIQUE)Edit: If you were only using that as an example, and the same question applies to using a class instead of an ID, Both ways should be relatively the same due to the way jquery works internally.
$(".elt", $this)converts to$this.find(".elt")which is identical to$this.find(".elt").You may find a difference between the two after running several thousand iterations of it at once, but in normal circumstances, you are better off using the one that is easier to read.