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


版本号 #2
由 壳壳虫 创建于 2026-10-31 03:27:53 UTC
由 壳壳虫 更新于 2026-10-31 03:27:53 UTC