Element.getAttributeNames
returns the attribute names of the element as an Array
of strings. If the element has no attributes it returns an empty array.
Using getAttributeNames along with Element.getAttribute
, is a memory efficient and performant alternative to accessing Element.attributes
.
Syntax
let attributeNames = element.getAttributeNames();
Example
// Iterate over element's attributes for(let name of element.getAttributeNames()) { let value = element.getAttribute(name); console.log(name, value); }
Specifications
Specification | Status | Comment |
---|---|---|
DOM The definition of 'Element.getAttributeNames' in that specification. |
Living Standard | Initial definition |