Last active
March 4, 2016 08:46
-
-
Save andreasvirkus/917a47fd8276be57300e to your computer and use it in GitHub Desktop.
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
/** | |
* author: andreas johan virkus | |
* snippet url: https://gist.github.com/andreasvirkus/917a47fd8276be57300e | |
* | |
* Return all classes found that match the given prefix | |
* Example: You have an element with classes "apple juiceSmall juiceBig banana" | |
* You run: | |
* $elem.returnClassPrefix('juiceS'); | |
* The resulting class is "juiceSmall" | |
* | |
* @return {Array} List consists of a concatenated string of classes that match the prefix per element iterated | |
*/ | |
$.fn.returnClassPrefix = function (prefix) { | |
var matchedClasses = []; | |
this.each( function ( i, it ) { | |
var classes = it.className.split(' ').map(function (item) { | |
return item.indexOf(prefix) === 0 ? item : ''; | |
}); | |
matchedClasses.push(classes.join(' ').trim()); | |
}); | |
return matchedClasses; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment