.setAttr(key, value)
Available on: InDom, InDomArraySets an attribute value to the underlying element.Parameters:
key {string} - Attribute key.
value {any} - Attribute value (will be coerced to string).
Returns: {InDom | InDomArray} - this for chainingThrows: Error - If the underlying element(s) 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: getAttr »