Skip to content

Instantly share code, notes, and snippets.

@rainyjune
Forked from bradwright/has-attribute.js
Last active December 13, 2015 16:48
Show Gist options
  • Save rainyjune/4942479 to your computer and use it in GitHub Desktop.
Save rainyjune/4942479 to your computer and use it in GitHub Desktop.
function hasAttribute(e, a) {
if(e.hasAttribute) return e.hasAttribute(a);
var fixAttr = {
tabindex: 'tabIndex',
readonly: 'readOnly',
'for': 'htmlFor',
'class': 'className',
maxlength: 'maxLength',
cellspacing: 'cellSpacing',
cellpadding: 'cellPadding',
rowspan: 'rowSpan',
colspan: 'colSpan',
usemap: 'useMap',
frameborder: 'frameBorder',
contenteditable: 'contentEditable'
};
var d = document.createElement("div");
d.setAttribute("class", "yuanJS");
var fullSupported = d.className === "yuanJS";
return !!e.getAttribute(fullSupported ? a : (fixAttr[a] || a));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment