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.


let attributeNames = element.getAttributeNames();


// Iterate over element's attributes
for(let name of element.getAttributeNames())
	let value = element.getAttribute(name);
	console.log(name, value);


​​​​​​​if (Element.prototype.getAttributeNames == undefined) {
  Element.prototype.getAttributeNames = function () {
    var attributes = this.attributes;
    var length = attributes.length;
    var result = new Array(length);
    for (var i = 0; i < length; i++) {
      result[i] = attributes[i].name;
    return result;


Specification Status Comment
The definition of 'Element.getAttributeNames' in that specification.
Living Standard Initial definition

Browser compatibility

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

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 ?

Document Tags and Contributors

Contributors to this page: mfuji09, Yaffle, jpmedley, tophf, adria
Last updated by: mfuji09,