-
-
Save rwaldron/478484 to your computer and use it in GitHub Desktop.
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
/* | |
Usages: | |
$(selector).classList() //returns an array of classnames | |
$(selector).classList('newclass') //replaces the current element's classes | |
$(selector).classList(['new', 'class', 'names']) //replaces the current element's classes | |
*/ | |
jQuery.fn.extend({ | |
classList: function( value ) { | |
if( value ){ | |
if( jQuery.isArray(value)){ | |
this.attr('class', '') | |
for(var i in value){ | |
this.addClass(value[i]) | |
} | |
return this; | |
} | |
if( typeof value == 'string'){ | |
this.attr('class', '').addClass(value); | |
return this; | |
} | |
} | |
return this.attr('class').split(/\s+/) | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment