The hasAttributes()
method returns true if the specified node has
any attributes, otherwise false.
hasAttributes |
Yes | 9 | Yes | Yes | Yes |
node.hasAttributes()
None
It returns a Boolean type value.
true if the node has attributes, otherwise false.
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: