Posted By

mlange on 10/03/06


Tagged

css jquery


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

bartekk
francisre
vali29
martingoldszein


jquery swapclass


 / Published in: JavaScript
 

  1. $.fn.swapClass = function(c1, c2){
  2. return this.each(function(){
  3. var t = $(this);
  4. (!t.is('.'+c1)) ?
  5. t.addClass(c1).removeClass(c2) : t.addClass(c2).removeClass(c1);
  6. });
  7. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: ernscht on February 7, 2008

or use $('.selector').toggleClass(c1).toggleClass(c2);

or as plugin

$.fn.swapClass = function(c1, c2) { return this.each(function(){ $(this).toggleClass(c1).toggleClass(c2); }); };

You need to login to post a comment.