Javascript Reference - HTML DOM hasAttributes Method








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

Browser Support

hasAttributes Yes 9 Yes Yes Yes

Syntax

node.hasAttributes()

Parameters

None

Return Value

It returns a Boolean type value.

true if the node has attributes, otherwise false.





Example

The following code shows how to see if the body element has any attributes.


<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<button onclick="myFunction()">test</button>
<script>
function myFunction()<!--from w  ww . j ava 2 s.c  om-->
{
    var x=document.getElementById("demo");
    x.innerHTML=document.body.hasAttributes();
}
</script>
</body>
</html>

The code above is rendered as follows: