Skip to content

Instantly share code, notes, and snippets.

@freality
Created March 27, 2013 18:23
Show Gist options
  • Save freality/5256760 to your computer and use it in GitHub Desktop.
Save freality/5256760 to your computer and use it in GitHub Desktop.
A jQuery method plugin that performs class name replacement.
/**
* jQuery method plugin replaceClass()
*
* Replace a class name with another within a selection.
*
*/
(function ($) {
// Add a method to the jQuery fn object.
$.fn['replaceClass'] = function(needle, replacement) {
return this
.filter(function() { return $(this).hasClass(needle); })
.each(function() {
$(this).removeClass(needle)
.addClass(replacement);
});
};
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment