Return to Snippet

Revision: 17425
at September 4, 2009 10:31 by quickredfox


Initial Code
/*
**  jquery.replaceClass.js -- jQuery "plugin", helps classname manip.
**  Copyright (c) 2007 Francois Lafortune (quickredfox.at)
**  Licensed under MIT 
**
*/
jQuery.fn.replaceClass = function(toReplace,replaceWith){
 return $(this).each(function(){
   return $(this).removeClass(toReplace).addClass(replaceWith);
 });
}

// Of course, you'd rarely ever save this file like this, what you wanna do
// is create a little extensions file for all your tiny little jQuery
// quirks and re-use that... 
jQuery.extend(jQuery.fn,{
replaceClass = function(){//code...},
otherHelper = function(){ //... }
// etc ...
})

Initial URL

                                

Initial Description
I notice a lot of addClass/removeClass.. thought maybe I'd post an example on how to simplify that....

Initial Title
jQuery.replaceClass();

Initial Tags
class, jquery

Initial Language
jQuery