W3cubDocs

/DOM

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 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 Webview Chrome for Android Firefox Mobile (Gecko) Firefox OS IE Mobile Opera Mobile Safari Mobile
Basic support 61 61 ? ? ? 48 ?

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/element/getAttributeNames