Firefox Tomorrow

web api instance method

Element: hasAttribute() method

View on MDN ↗

The Element.hasAttribute() method returns a Boolean value indicating whether the specified element has the specified attribute or not.

Syntax

hasAttribute(name)

Parameters

  • name
    • : is a string representing the name of the attribute.

Return value

A boolean.

Examples

const foo = document.getElementById("foo");
if (foo.hasAttribute("bar")) {
  // do something
}

Specifications

SpecificationsStandards references are available on the canonical MDN page.

Browser compatibility

Browser compatibilityCompatibility data is available on the canonical MDN page.

See also