Thanks for all your responses. I actually do all the things that you mentioned: reusing the jQ object, chaining, setting a context, etc. Actually it would be helpful to have some performance analysis on the different kinds of queries, such as searching by ID, by element, class name, attribute, xpath queries, context-delimited, etc., because even though it's somewhat straightforward to know that a search by ID is faster than searching by class name, it'd be interesting (and useful) to know by how much.


 
On 10/7/06, Matt Stith <[EMAIL PROTECTED]> wrote:
yes, that would help quite a bit, since jquery would only need to look once.

On 10/7/06, Jacky < [EMAIL PROTECTED]> wrote:
> Would caching the jQuery object a help too? Sometimes you just can't
> keep the chain.
>
> e.g. var jqObj = $("#abc");
>
> On 10/8/06, Karl Swedberg <[EMAIL PROTECTED]> wrote:
> > On Oct 7, 2006, at 3:39 PM, George Adamson wrote:
> >
> > > An easy performance booster is to use the second param in $() to set a
> > > context for the search. Eg: $("DIV.myClass", myParentElement).
> > > Perhaps this
> > > is what you meant when you mentioned 'getting a parent element' ?
> > >
> > > Chaining methods is helpful so you can avoid re-querying. If you
> > > need to put
> > > other code in betwen method calls then reusing the same JQuery
> > > object by
> > > putting it into a variable beforehand is worth while to save
> > > requerying.
> > >
> > > If you're going to do several queries inside the same parent element
> > > (s) then
> > > a combination of the above will be a big help.
> >
> > Those sound like good suggestions to me, though I'm no expert.
> >
> > Something I try to keep in mind is the relative speed of different
> > types of queries. This has been mentioned on the list before, but in
> > case you didn't see it, references to IDs are fastest, followed by
> > elements, and then classes. At least, that's how I've understood
> > previous discussions of the topic. So:
> > a.  $('#my-id') is faster than $('div#my-id'), and
> > b. $('div.my-class') is faster than $('.my-class')
> >
> > Hop that helps.
> >
> > Karl
> > _______________________
> > Karl Swedberg
> > www.englishrules.com
> > www.learningjquery.com
> >
> >
> > _______________________________________________
> > jQuery mailing list
> > discuss@jquery.com
> > http://jquery.com/discuss/
> >
>
>
> --
> Best Regards,
> Jacky
> 網絡暴民 http://jacky.seezone.net
>
> _______________________________________________
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/
>

_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to