tags:

views:

146

answers:

3

Here is the div element on my page:

How can I change a class's content?

So from existing which is: class="jcarousel-next jcarousel-next-horizontal"

to class="jcarousel-next jcarousel-next-horizontal jcarousel-next- disabled jcarousel-next-disabled-horizontal"

Do I need to completely remove it by using removeClass and then re-add?

+4  A: 

The addClass function preserves existing classes.

Andrew Hare
+3  A: 

no you can just use addClass. if you add a class that is already there jQuery wont add it again

$('#myelem').addClass('jcarousel-next-disabled jcarousel-next-disabled-horizontal');
howardr
choose this answer because it was put into context for me with an example..otherwise I get that it preserves it...ok but what does that mean to me in terms of use of this..I did not know that thus you can just override that class by specifying it's content like this. This is part of why I hate open source documentation, too many inferred things after a one line sentence.
CoffeeAddict
A: 

Try this:

jQuery('#myobj').removeClass('class-to-remove').addClass('class-to-add');

EDIT: multiple classes at once:

jQuery('#myobj').removeClass('class1 class2').addClass('class3 class4');

Also you can toggle classes with toggleClass().

Brg.

hegemon