Created
March 27, 2013 18:23
-
-
Save freality/5256760 to your computer and use it in GitHub Desktop.
A jQuery method plugin that performs class name replacement.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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