.getAttr(key)
Available on: InDomGets the value of an attribute of the underlying element.Parameters:
key {string} - The attribute key.
Returns: {string | null} - The attribute , null if the attribute doesn't existThrows: 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: hasAttr »