Last active
May 13, 2018 20:30
-
-
Save dmhendricks/ec6a833ce9980a1e78236824756358cb to your computer and use it in GitHub Desktop.
jQuery function to replace one or more CSS classes with others.
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 function to replace one or more CSS classes with others. Separate multiple | |
* classes with spaces. | |
* @param {string} remove - CSS classes to remove. | |
* @param {string} add - CSS classes to add. | |
* @example | |
* $( '.selector' ).replaceClass( 'old-class', 'new-class some-other-class' ); | |
* $( '.selector' ).replaceClass( 'old-class another-class', 'new-class' ); | |
*/ | |
!function(s){s.fn.replaceClass=function(remove,add){var e=add||remove;return e&&this.removeClass(add?remove:this.className).addClass(e),this}}(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment