Tuesday, December 14, 2010

jQuery add class to element: How to add a class to a div

Adding class or removing a css class from an element with jQuery or Prototypejs is very simple.



// With JQuery

$('#target').addClass('bar');

// With Prototypejs...

$('target').addClassName('bar');

// Removing a class with Jquery

$('#target').removeClass('bar');

// With Prototypejs...
$('target').removeClassName('bar');



Once again, jQuery has shorter function names which is awesome!