i would the best thing to do regardless of your selection method is to store
them in variables.

like this

var obj = $(".wrap");

Now you have basically created an object reference point. you won't need to
re-create in 99% of cases.

so lets re-use our object reference.

// get the width of your object without making a new reference
var obj_width = obj.width();
// get a child element in your object without making a new reference to your
object
// also you are only searching within your object, not the whole page.
performance boost here
var element_in_object = $(".elementclass", obj);

//if you only need to make one reference in your whole script theres no need
to make so //many vars.
//you can point directly to it
// this would be more efficient if you don't need to reference your "wrap"
class again
var my_element = $(".wrap .elementclass");

I already know theres gonna be people ready to debate on their methods :)
but this is my thoughts.



On Tue, Nov 10, 2009 at 5:47 PM, Michel Belleville <
michel.bellevi...@gmail.com> wrote:

> As to the why I don't know, but as to the which the solution is quite easy
> : do a benchmark.
>
> Michel Belleville
>
>
> 2009/11/10 Adam Tistler <atist...@gmail.com>
>
>> I am using jquery 1.3.2.  I was wondering which is faster and why:
>>
>> $('#my-id .main table tr.my-class') or
>> $('#my-id > .main > table > tr.my-class') or
>> $('#my-id tr.my-class')
>>
>>
>>
>>
>>
>

Reply via email to