Javascript Reference
Categories: Node

javascript Node attributes[ ]

@March 15, 2008, 1:22 a.m.
attributes[ ]Firefox/Netscape/NN 6 IE 5 Chrome/Safari/DOM 1   

Read-only  

Returns a named node map object, which resembles an array (collection) of attribute objects (W3C DOM type Attr), but also has some methods of its own to facilitate accessing a member of this array. IE's attributes array contains entries for all attributes of the element's internal DTD, plus any custom (expando) attributes explicitly set in the HTML source code in IE 6. Scripted changes to the element's attributes or their values are not reflected in this array.

 

For Netscape 6, the attributes array contains entries only for those attributes explicitly defined in the HTML source code for the element, including custom attributes. Scripted changes to attributes (additions or deletions) or their values are reflected in the attribute objects referenced by the attributes array.

 

In lieu of the named node map object methods, you may access individual attribute objects via standard JavaScript array syntax. By and large, however, it is far more convenient to access HTML element attribute values for scripting purposes either via their reflection as element object properties or via the element's getAttribute( ) and setAttribute( ) methods. For W3C DOM details (which are useful for XML document parsing), see the Attr and NamedNodeMap objects for properties and methods of these objects.

 
Example
 
var ldAttr = document.getElementById("myImg").attributes.getNamedItem("longdesc");
 
Value

Array (collection) of attribute object references in source code (Netscape 6), alphabetical-by-name (IE/Mac), or haphazard (IE/Windows) order.

 
Default

Current element's model.

Under moderation.
vhslztuv - 2014-04-01
Under moderation.
eqtvpafh - 2014-03-25
Under moderation.
mqyiujbv - 2014-03-24

Powered by Linode.