hasAttributes (W3C DOM Core method)

Version Depr. Static
DOM2 No No
Browser support (more…)
IE7 FF1.5+ SA1.3+ OP9+
None Full Full Full


var hasattrs = node.hasAttributes();

In the example above, the variable hasattrs will have the value true if node is an element and has any attributes, otherwise it will be false.

So in this next HTML example, if node were the first paragraph then hasAttributes would return true. But if node were the second paragraph, which has no attributes, then hasAttributes would return false:

<p id="first"><q>I am the eggman</q></p>

<p><q>I am the walrus</q></p>


Returns whether an Element node has any attributes.

Return value

Returns true if this node is an Element and has any effective attributes, otherwise false


Internet Explorer Firefox Safari Opera
5.5 6.0 7.0 1.5 2.0 3.0 1.3 2.0 3.0 9.0 9.5
None None None Full Full Full Full Full Full Full Full

Internet Explorer doesn't implement this method, and will throw an error if it's used.

: Implicit attributes are not included in all browsers

Internet Explorer, Firefox, Safari and Opera 9.5 do not include attributes which are not explicitly defined but have a specific default value in this document type, such as the shape attribute of an <a> element (only Opera 9.0 does so).

However for this method, the specification does not actually say whether it means any effective attributes1, or merely explicitly-defined attributes. I suspect that it intended to mean effective attributes, but in the absence of specification this behavior cannot be considered a bug.


1 Either explicitly defined attributes, or attributes which have a specific default value in this document type, such as the shape attribute of an a element. See Attr for details.

User-contributed notes

There are no comments yet.

Related Products