[jQuery] Re: .removeClass() performance is very low on IE7
Thanks! I had fixed my code and your answer inspired me to map the elements with the class into an array. My script become more responsive now. On Jul 8, 8:31 pm, "Joel Birch" <[EMAIL PROTECTED]> wrote: > Hi Evert, > > '.someclass' is a slow selector as it has to check every single > element on the page to see if it matches class="someclass". Limiting > the search closer to the desired elements will speed up the selection > hugely. For example, choose the closest common ancestor that all > potential target elements share and that has an id (say, > #somecontainer) and also specify the type of element that the target > will be if possible (in this case, a div). Your improved code would > look like this: > > // find all divs with class 'someclass' that are somewhere within > // (descendant of) an element with id 'somecontainer': > > $('#somecontainer div.someclass').removeClass['someclass'); > > Please let us know if your code still seems slow in IE7 after this. > > Joel Birch.
[jQuery] Re: .removeClass() performance is very low on IE7
Be sure to change that [ to a ( so it will work. :) On Jul 8, 8:31 am, "Joel Birch" <[EMAIL PROTECTED]> wrote: > Hi Evert, > > '.someclass' is a slow selector as it has to check every single > element on the page to see if it matches class="someclass". Limiting > the search closer to the desired elements will speed up the selection > hugely. For example, choose the closest common ancestor that all > potential target elements share and that has an id (say, > #somecontainer) and also specify the type of element that the target > will be if possible (in this case, a div). Your improved code would > look like this: > > // find all divs with class 'someclass' that are somewhere within > // (descendant of) an element with id 'somecontainer': > > $('#somecontainer div.someclass').removeClass['someclass'); > > Please let us know if your code still seems slow in IE7 after this. > > Joel Birch.
[jQuery] Re: .removeClass() performance is very low on IE7
Hi Evert, '.someclass' is a slow selector as it has to check every single element on the page to see if it matches class="someclass". Limiting the search closer to the desired elements will speed up the selection hugely. For example, choose the closest common ancestor that all potential target elements share and that has an id (say, #somecontainer) and also specify the type of element that the target will be if possible (in this case, a div). Your improved code would look like this: // find all divs with class 'someclass' that are somewhere within // (descendant of) an element with id 'somecontainer': $('#somecontainer div.someclass').removeClass['someclass'); Please let us know if your code still seems slow in IE7 after this. Joel Birch.
[jQuery] Re: .removeClass() performance is very low on IE7
The code is simple... .simpleclass{ opacity: 0.5; background: green; } ... $(function() { $(".simpleclass").removeClass("simpleclass"); } ); P/S: I had made a mistake in my previous post. It is not an id. It is a class. On Jul 3, 12:37 am, spicyj <[EMAIL PROTECTED]> wrote: > Can you give a sample page? I'm confused about what you mean by "only > 2 elements to remove". > > On Jul 2, 9:51 am, Evert <[EMAIL PROTECTED]> wrote: > > > //only 2 elements to remove > > $("#id").removeClass('onesimpleclassonly'); > > > It took almost 3 ~ 4 seconds to remove the class. > > What can I do to speed up the process?
[jQuery] Re: .removeClass() performance is very low on IE7
Why are you using an ID on 2 different elements? On Jul 2, 11:51 am, Evert <[EMAIL PROTECTED]> wrote: > //only 2 elements to remove > $("#id").removeClass('onesimpleclassonly'); > > It took almost 3 ~ 4 seconds to remove the class. > What can I do to speed up the process?
[jQuery] Re: .removeClass() performance is very low on IE7
Can you give a sample page? I'm confused about what you mean by "only 2 elements to remove". On Jul 2, 9:51 am, Evert <[EMAIL PROTECTED]> wrote: > //only 2 elements to remove > $("#id").removeClass('onesimpleclassonly'); > > It took almost 3 ~ 4 seconds to remove the class. > What can I do to speed up the process?