Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to override a class using jquery

A 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 can this class be overridden and a new class added so that I can put different styles in it? Maybe I have to remove before classes before adding them. How is this done?

Thanks

like image 565
Hulk Avatar asked Feb 24 '10 13:02

Hulk


2 Answers

Use the class selector with addClass and removeClass.

$('.newwidget').removeClass('newwidget').addClass('newerwidget');
like image 92
tvanfosson Avatar answered Sep 26 '22 10:09

tvanfosson


I think it's worth noting that you can remove all the classes by leaving off the parameter from removeClass():

$('.newwidget').removeClass().addClass('newerwidget');
like image 32
Tom Rossi Avatar answered Sep 24 '22 10:09

Tom Rossi