attrName – the name of the attribute to check for (required).
Returns:
''true'' if the attribute exists, ''false'', if not.
Notes:
* This function can be used to check if empty attributes (like [[mdn>Web/HTML/Global_attributes/hidden|hidden]], [[mdn>Web/HTML/Element/details#attributes|open]], etc.) are present, which is not possible with the [[toolbox:element:getattr:index|.getAttr()]] function.
* This is just a simple wrapper for the JavaScript built-in [[mdn>Web/API/Element/hasAttribute|hasAttribute]] method. If you don't need command chaining, it is more efficient to use ''.hasAttribute(…)'' instead.
===== Example =====
let foo = document.getElementById('foo');
if (foo.hasAttr('bar')) {
…
}
===== See also =====
* [[toolbox:element:getattr:index|.getAttr()]]
* [[toolbox:element:setattr:index|.setAttr()]]
===== More information =====
* [[mdn>Web/API/Element/hasAttribute|Element: hasAttribute() method]] on MDN