Element.getAttributeNames

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

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 61 45 (45) No support 48 9
Feature Android Android Webview Firefox Mobile (Gecko) Firefox OS IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support ? 61 ? ? ? ? ? 61

Document Tags and Contributors

 Contributors to this page: tophf, adria
 Last updated by: tophf,