Reputation: 47733
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?
Upvotes: 2
Views: 1019
Reputation: 6764
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.
Upvotes: 0
Reputation: 333
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');
Upvotes: 3