JSFiddle - React, Tailwind, and code Playground
by AndyE
HTML
<div style="display:none;">
<input value="">
<input>
<input type="checkbox" checked>
</div>
JavaScript
function hasAttribute(el, attr) {
if ("hasAttribute" in el && (!document.documentMode || document.documentMode > 8)) {
// IE 8 bug returns false for some hasAttribute checks, so
return el.hasAttribute(attr);
}
else if ("outerHTML" in el) {
return (el.outerHTML
// remove content
.replace(el.innerHTML, "")
// remove attribute values with quotes
.replace(/=(?:(["'])[^\1]*\1)?/, " ")
// remove attribute values without quotes
.replace(/=[^\s>]+/, "")
// normalize
.toLowerCase()
// search for attribute
.indexOf(" " + attr.toLowerCase()) > -1);
}
}
$("input").each(function (i, el) {
var attrs = $.map(["value", "type", "checked"], function (attr) {
return hasAttribute(el, attr) && attr || null;
});
$(document.body).append("<div>"+el.tagName+":<i> "+ attrs.join(", ") + "</i></div>");
});