Created
April 8, 2015 19:06
-
-
Save jmmcduffie/964f2a6069d642b22e2b to your computer and use it in GitHub Desktop.
Data Attribute Object
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
function extractDataObjects(node) { | |
var objects = {}, | |
attributes = [].slice.call(node.attributes); | |
attributes.forEach(function(attribute) { | |
if (/^data-/.test(attribute.nodeName)) { | |
objects[attribute.nodeName.slice(5)] = attribute.value; | |
} | |
}); | |
return objects; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment