.hasAttr(key)
Available on: InDomChecks if the underlying element has an attribute.Parameters:
key {string} - The attribute key.
Returns: {boolean} - true if the attribute exists, false otherwise.Throws: Error: If the underlying element has been removed
Examples:const img = $n('<img src="example-star.png" width="50" height="50">');
// helper: return attr value if the attribute exists or 'no alt' if doesn't
const getImgAlt = () => img.hasAttr('alt') ? img.getAttr('alt') : 'no alt';
console.log(`img alt:${getImgAlt()}`); // no alt
img.setAttr('alt','example image');
console.log(`img alt:${getImgAlt()}`); // example image
img.removeAttr('alt');
console.log(`img alt:${getImgAlt()}`); // no altNext: removeAttr »