This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

hasAttributes

Summary

Returns whether this node (if it is an element) has any attributes

Method of dom/Nodedom/Node

Syntax

var bResult = object.hasAttributes();

Return Value

Returns an object of type BooleanBoolean

true if this node has any attributes, false otherwise.

Examples

The following example will display an alert message that "the root element has attributes’. No following alert is displayed for the body element as it has no attributes.

<!DOCTYPE html>
<html id="root" class="desktop">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>hasAttributesExample</title>
</head>

<body>
<script type="text/javascript">
var re=document.getElementById('root');
if(re.hasAttributes()){alert('the root element has attributes');}
var be=document.body;
if(be.hasAttributes()){alert('the body element has attributes');}
</script>
</body>

</html>

Notes

Remarks

The hasAttributes method determines whether the object has any attributes at all. The hasAttribute method tests for the existence of a specified attribute.

Related specifications

DOM Level 2 Core
Recommendation

Attributions