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

