Skip to content

Instantly share code, notes, and snippets.

@danwoods
Last active October 7, 2015 15:48
Show Gist options
  • Save danwoods/3189124 to your computer and use it in GitHub Desktop.
Save danwoods/3189124 to your computer and use it in GitHub Desktop.
getDataFromClasses(elm, identifier)
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