3 function toAttribute(name) {
4 var attribute = name.replace(/[A-Z]/g, function(a) {
5 return '-' + a.toLowerCase();
8 return 'data-' + attribute.toLowerCase();
11 if (document.documentElement.dataset) {
12 // Handle modern browsers
14 get: function(element, name) {
15 return element && element.dataset && element.dataset[name];
17 set: function(element, name, value) {
18 element.dataset[name] = value;
22 // Handle old internet explorer versions
24 get: function(element, name) {
25 return element && element.getAttribute(toAttribute(name));
28 set: function(element, name, value) {
29 return element.setAttribute(toAttribute(name), value);