Here's a rough outline of the code/style in question.

My plugin will position an element in one of 16 predefined locations and add
a css class pertaining to that location (eg. location1). It knows nothing
about the element it's positioning. When it adds the location css class it
first has to remove any existing location classes (16 total) as an element
could have been previously positioned. The location css classes have no
style but are used as selectors for an element.

.location0 img.foo {
    left: 0px;
}
.location1 img.foo {
    left: 10px;
}

The final code in question is along the lines of:
$(element).removeClass('location0 location1 ...
location15').addClass('location' + n);

-js



On 9/19/07, Andy Matthews <[EMAIL PROTECTED]> wrote:
>
>  I might argue that if you're having to add/remove 15 classes, that your
> time could be better spent optimizing your display code.
>
>
> andy
>
>  ------------------------------
> *From:* jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] *On
> Behalf Of *Jonathan Sharp
> *Sent:* Wednesday, September 19, 2007 11:55 AM
> *To:* jquery-en@googlegroups.com
> *Subject:* [jQuery] PERFORMANCE TIP: removeClass()
>
>
>  *Do not do:*
> $(...).removeClass('a').removeClass('b').removeClass('c');
>
> *Instead do:*
> $(...).removeClass('a b c');
>
> Same applys to addClass()
>
> I had 15 classes I had to remove and Firefox was a champ at chained
> removeClass calls, IE was taking 760ms!
>
> -js
>

Reply via email to