Last active
September 16, 2015 16:39
-
-
Save goodpixels/da1df0dcd102806fcf0f to your computer and use it in GitHub Desktop.
Remove all classes except for the ones given.
This file contains hidden or 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
/*! (c) 2015 John Przeslakowski | Code released under the MIT license | goodpixels.co.uk */ | |
( function ( $ ) { | |
$.fn.removeClassExcept = function ( val ) { | |
return this.each( function( index, el ) { | |
var keep = val.split( ' ' ); | |
var reAdd = []; | |
var $el = $(el); | |
for( var c = 0; c < keep.length; c++ ) { | |
if( $el.hasClass( keep[ c ] ) ) reAdd.push( keep[ c ] ); | |
} | |
$el.removeClass().addClass( reAdd.join( ' ' ) ); | |
} ); | |
}; | |
}( jQuery ) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment