I\'m playing around with the attr-data-* attributes of HTML5 and the corresponding javascript dataset
I\'m doing alot of dynamic form processing, so I end up getting
Here's a little function to retrieve the element dataset as a normal object:
function datasetToObject(elem){
var data = {};
[].forEach.call(elem.attributes, function(attr) {
if (/^data-/.test(attr.name)) {
var camelCaseName = attr.name.substr(5).replace(/-(.)/g, function ($0, $1) {
return $1.toUpperCase();
});
data[camelCaseName] = attr.value;
}
});
return data;
}
Scooped up from: Get list of data-* attributes using javascript / jQuery