Back to Content

Element: hasAttributes() method

files/en-us/web/api/element/hasattributes/index.md

latest747 B
Original Source

{{ApiRef("DOM")}}

The hasAttributes() method of the {{domxref("Element")}} interface returns a boolean value indicating whether the current element has any attributes or not.

Syntax

js-nolint
hasAttributes()

Parameters

None.

Return value

A boolean.

Examples

js
let foo = document.getElementById("foo");
if (foo.hasAttributes()) {
  // Do something with 'foo.attributes'
}

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also

  • {{domxref("Element.attributes")}}
  • {{domxref("Element.hasAttribute()")}}
  • {{domxref("Element.getAttribute()")}}
  • {{domxref("Element.setAttribute()")}}
  • {{domxref("Element.removeAttribute()")}}
  • {{domxref("Element.toggleAttribute()")}}