docs.rodeo

MDN Web Docs mirror

Element: hasAttribute() method

{{APIRef("DOM")}} 

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

Syntax

hasAttribute(name)

Parameters

Return value

A boolean.

Examples

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

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN