The second parameter of the Element.setAttribute()
(JS/DOM) is redundant when setting a boolean attribute. So it would probably make sense to make it optional, so that the following calls are equivalent:
example.setAttribute('data-mybool', '');
example.setAttribute('data-mybool');
If the boolean attribute to set already exists, the method should probably do nothing.
A proof-of-concept polyfill:
(function() {
var nativeFunction = Element.prototype.setAttribute;
Element.prototype.setAttribute = function(name, value) {
if ('undefined' === typeof value) {
if (this.hasAttribute(name)) {
return;
}
this.setAttribute(name, '');
}
else {
nativeFunction.call(this, name, value);
}
};
})();