HTML DOM Element hasAttributes() method

Definition and usage

If the specified node has attributes, then hasAttributes() The method returns true, otherwise returns false.

If the specified node is not an element node, the return value is always false.

See also:

getAttribute() method

setAttribute() method

removeAttribute() method

hasAttribute() method

getAttributeNode() method

setAttributeNode() method

removeAttributeNode() method

Tutorial:

HTML Attributes

Example

Does the <body> element have attributes?

let answer = document.body.hasAttributes();

Try it yourself

Syntax

element.hasAttributes()

or

node.hasAttributes()

Parameter

None.

Return value

Type Description
Boolean value Returns true if the element has attributes, otherwise false.

Browser support

element.hasAttributes() It is a DOM Level 2 (2001) feature.

All browsers fully support it:

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
Support 9-11 Support Support Support Support