Created
June 20, 2012 19:51
-
-
Save ledbettj/2961819 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
| function nameToCamel(name) { | |
| words = name.split(/[-_]/); | |
| for(var i = 0; i < words.length; ++i) { | |
| words[i] = words[i].substr(0, 1).toUpperCase() + words[i].substr(1); | |
| } | |
| return words.join(''); | |
| } | |
| var node = document.getElementById("test"); | |
| var attrs = {}; | |
| for(var i = 0; i < node.attributes.length; ++i) { | |
| var attr = node.attributes[i]; | |
| if (attr.name.match(/^data-/)) { | |
| attrs[nameToCamel(attr.name.substr(5))] = attr.value; | |
| } | |
| } | |
| /* TADA */ | |
| console.log(attrs); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment