Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery changing css class to div

Tags:

html

jquery

css

If I have one div element for example and class 'first' is defined with many css properties. Can I assign css class 'second' which also has many properties differently defined to this same div just on some event without writing each property in line.

like image 341
eomeroff Avatar asked Dec 02 '09 20:12

eomeroff


2 Answers

Yep, easily.

$("#mydiv").attr("class", "second"); 
like image 171
womp Avatar answered Sep 24 '22 13:09

womp


$(".first").addClass("second"); 

If you'd like to add it on an event, you can do so easily as well. An example with the click event:

$(".first").click(function() {     $(this).addClass("second"); }); 
like image 25
Mark Hurd Avatar answered Sep 22 '22 13:09

Mark Hurd