value (W3C DOM Core property)

Version Depr. Static Read-only
DOM1 No No No
Browser support (more…)
IE6+ FF1.5+ SA3+ OP9+
Buggy Full Full Buggy


var attrs = document.documentElement.attributes;

for(var i=0; i<attrs.length; i++)
  var val = attrs[i].value;

In the example above we create a reference to the documentElement attributes collection, then we iterate through the collection numerically and retrieve the value of each individual attribute.


The value of an Attr node.

When retrieving, this is a parsed string (ie. entities have been expanded) containing the value of the attribute. When setting, the specification states that a Text node should be created containing the specified string (which is unparsed, so even if it contains characters that an interpretor would recognize as markup, these are treated as literal text). However in practise this is usually not the case, and a DOMString value is created instead; please see Attr for more details.

The value of an Attr node is exactly the same as its nodeValue.

This property is read/write.


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
Partial Buggy Buggy Full Full Full Buggy Buggy Full Buggy Buggy

In Safari 1.3 and 2 this property is readonly (ie. it cannot be used to set the value, only retrieve it).

Internet Explorer 6 and 7 in HTML return null for the value of a style attribute.

Internet Explorer 5.5 in HTML cannot retrieve attribute nodes, only attribute values; although attribute values do inherit the nodeValue property of Node, they do not expose a value property (it returns undefined).

Opera 9.0 in pure XML (but not XHTML mode1) parses entities when setting the value of an attribute (contrary to the specification).


1 On XHTML pages served as application/xhtml+xml.

User-contributed notes

There are no comments yet.

Related Products