• Is there any better way to rewrite this:
jQuery Code
$('element').removeClass('class1').removeClass('class2');
  • Can’t use removeClass(); as it would remove ALL classes, which we don’t want.1

jQuery Code
$("element").removeClass("class1 class2");
  • From removeClass(), the class parameter:
  • One or more CSS classes to remove from the elements, these are separated by spaces.

  • This is one of the solution :
javascript code
$('element').removeClass('class1 class2');
[ad type=”banner”]

  • One or more CSS classes to remove from the elements, these are separated by spaces.

We can do this :

  • class (Optional) String
  • One or more CSS classes to remove from the elements, these are separated by spaces.

Example:

  • Remove the class ‘blue’ and ‘under’ from the matched elements.
jQuery Code
$("p:odd").removeClass("blue under");

  • Remove the class name “intro” from all ements:
javascript Code
$("button").click(function()
{
$("p").removeClass("intro");
}

[ad type=”banner”]

 

Categorized in: