attrName – the name of the attribute to return (required).
Returns:
The value of the attribute as [[mdn>Web/JavaScript/Reference/Global_Objects/String|String]], or an //empty// string if the attribute either does not exist, or if it is an //empty attribute// (i.e. it has no value).
Notes:
* To check if an empty attribute exists, use [[toolbox:element:hasattr:index|.hasAttr()]] instead.
===== Examples =====
Simple example:
const it = document.getElementById('item')
console.log(it.getAttr('foo'));
===== See also =====
* [[toolbox:element:hasattr:index|.hasAttr()]]
* [[toolbox:element:setattr:index|.setAttr()]]
===== More information =====
* [[mdn>Web/API/Element/getAttribute|Element: getAttribute() method]] on MDN.