getAttribute → string or null. Missing names return null.
Empty string is present.title="" → hasAttribute is true.
Pick the right tool. Guard with hasAttribute; read with getAttribute.
Compatibility
Browser Support
Element.hasAttribute() is Baseline Widely available (MDN: across browsers since July 2015). Safe to use without a polyfill in modern teaching and production code.
✓ Baseline · Widely available
hasAttribute()
Return true or false depending on whether a named attribute exists on the element.
WideBaseline
Google ChromeFull support
Supported
Mozilla FirefoxFull support
Supported
Apple SafariFull support
Supported
Microsoft EdgeFull support
Supported
OperaFull support
Supported
Internet Explorer8+
Supported
hasAttribute()Widely available
Bottom line: Use hasAttribute whenever you need a clear existence check before reading or acting on an attribute.
Frequently Asked Questions
It returns a boolean indicating whether the element has the specified attribute, regardless of the attribute’s value (MDN).
No. MDN marks Element.hasAttribute() as Baseline Widely available (across browsers since July 2015). It is not Deprecated, Experimental, or Non-standard.
false. When the attribute is present — even with an empty string value — it returns true.
hasAttribute() returns true/false for existence only. getAttribute() returns the attribute value as a string, or null when the attribute is missing.
Yes. If the disabled attribute is present on an element, hasAttribute('disabled') returns true even when the attribute has no value.
It is a clear, readable guard when you only need to know if an attribute exists before reading or acting on it.