views:

230

answers:

4

All,

A class jquery css class sets the following .

 .newwidget { border: 1px solid #5a9ee9; background: #5a9ee9 url(t6.gif) 50% 50% repeat-x; color: #ffffff; font-weight: bold; text-transform: uppercase; padding:3px 3px 3px 10px; font-size:10px}

How to override this class and add a new class so that i can put different styles in it.May be i have to remove and add class.How is this done.

Thanks..

+9  A: 

Use the class selector with addClass and removeClass.

$('.newwidget').removeClass('newwidget').addClass('newerwidget');
tvanfosson
+3  A: 

You can to remove the old class and add a new one:

$myJQObject.removeClass('newwidget').addClass('newclass');
nickf
+4  A: 

jQuery defines addClass() and removeClass() for just this purpose:

$("#ElementId").removeClass('oldClassName').addClass('newClassName');

The two function do the obvious. Chain them like this to change the class all in one action.

If you would like to change all elements from 'oldClass' to 'newClass', you can use a selector like this:

$(".oldClassName").removeClass('oldClassName').addClass('newClassName');
Aaron
Thanks for the explaination
Hulk
+1  A: 
$(this).removeClass('oldClass').addClass('newClass');
x4tje