Great, thanks for that Erik. I'll try a few things and see how I go. I wasn't
asking for a rewrite of the whole thing, just some pointers :>



Erik Beeson wrote:
> 
> I don't have time to rewrite your whole example, but I can offer a few
> tips
> that might help. Selecting by class alone can be pretty slow. Basically
> every single tag has to be checked for the class every time you do a
> selection by class. It would help to at least give the HTML tag that the
> class is being applied to, like $('li.current_page_item').
> You do quite a few next/prev/addClass calls on the same elements, but
> you're
> reselecting them every time. I suggest you use the "end" function.
> Operations that modify what elements are selected work as a stack, and
> allow
> you to "undo" operations, like so:
> 
> $(".current_page_item").next().addClass('after').end().prev().addClass('before');
> $(".current_page_ancestor").next().addClass('after').end().prev().addClass('before');
> 
> Calls to the $ function are often expensive, so it can help to cache them
> in
> a local variable if you find you're calling $ with the same parameter
> multiple times.
> 
> For that repetitive stuff you're doing at the end, I suggest you look into
> the "each" function.
> 
> Hope it helps.
> 
> --Erik
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Help-optimising-jquery-code---there-must-be-a-better-way-tp20082703s27240p20098334.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.

Reply via email to