Last active
October 7, 2015 15:48
-
-
Save danwoods/3189124 to your computer and use it in GitHub Desktop.
getDataFromClasses(elm, identifier)
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
var getDataFromClasses = function(elm, identifier){ | |
var classes = jQuery(elm).attr('class').split(' '), | |
data = '', | |
regex = new RegExp(identifier); | |
// Loop though classes | |
for(var i = 0; i < classes.length; i++){ | |
// If current class matches the identifier, extract data | |
if(regex.test(classes[i])){ | |
data = classes[i].replace(identifier, ''); | |
break; | |
} | |
} | |
// Return data | |
return data; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment