$('.myclass') is, as you've noticed, pretty slow because it has to search
through the *entire* page looking for element with a class of "myclass".

There are a couple things you can do:

If you know that all of the elements you want are, say, <div>'s, then

$('div.myclass');

is going to be a lot faster

If you know that all of the element you want are children of a particular
element, then you could do

$('.myclass', contextElement);

which will restrict jQuery's search to contextElement (instead of the entire
page)

On 11/16/06, Matthew Delmarter <[EMAIL PROTECTED]> wrote:

 Hi all,

I am using the $('.myclass') approach quite a lot, but am finding it is
slowing down my pages when used a lot. Is there an alternative method I can
use in jQuery that is faster? What about Xpath - any tips?

Thanks for you help...

 Matthew

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/



_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to