HTML DOM Element hasAttributes()
Example
Does the <body> element have attributes?
let answer = document.body.hasAttributes();
Try it Yourself »
Definition and Usage
The hasAttributes()
method returns true
if a node has attributes,
otherwise false
.
The hasAttributes()
method always returns false
if the node is not an element node.
Syntax
element.hasAttributes()
or
node.hasAttributes()
Parameters
NONE |
Return Value
Type | Description |
Boolean |
true if the element has attributes, otherwise false . |
Browser Support
element.hasAttributes()
is a DOM Level 2 (2001) feature.
It is fully supported in all browsers:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | 9-11 | Yes | Yes | Yes | Yes |