DOM Element.hasAttribute() Method
The hasAttribute() method checks whether an element has a given attribute.
Description
The hasAttribute() method returns whether the element has the named attribute at all, regardless of its value. It's the natural way to test boolean attributes.
The check is case-insensitive for HTML elements and ignores the value entirely, so hidden="false" still counts as present. To check whether an element has any attributes at all, use hasAttributes().
For attributes that have a matching boolean property, such as disabled, checked and open, reading the property is often simpler and reflects the element's current state, which can differ from the attribute for some form controls.
Syntax
element.hasAttribute(name)Parameters
- nameThe name of the attribute.
Return Value
true if the element has the attribute, otherwise false.
Example
Browser Support
The following information will show you the current browser support for the Element.hasAttribute() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





