Attribute object (Object/DOM)

A DOM object that represents an HTML tag attribute.

Availability:

DOM level - 1
JavaScript - 1.5
JScript - 5.0
Internet Explorer - 5.0
Netscape - 6.0
Inherits from:Node object
JavaScript syntax:-myAttribute = myAttributes.aPropertyName
-myAttribute = myAttributes[anIndex]
-myAttribute = myAttributes[aName]
-myAttribute = myDocument.createAttribute(aName)
Argument list:aPropertyNameThe name of the tag attribute
aNameAn attribute name
anIndexA valid numeric reference to an element in the collection
Object properties:name, nodeName, nodeType, nodeValue, specified, value

This is used by the browser to maintain property values for HTML tag instantiated objects.

This object represents a single HTML tag attribute. The properties of this object indicate whether the tag attribute has been specified or not, and if it has, what the current value is.

The Element object should contain enough information for you to be able to determine the instantiating source tag name. The attributes can be inspected with a script and the complete source HTML reconstructed from a combination of the information supplied by the element and its associated attributes collection.

The attributes collection that belongs to an object also tells you what the expected complete set of attributes are for the tag, although this may not be completely reliable.

The example script demonstrates how you can make an Attribute object inspector with a fragment of JavaScript. These inspectors can be put into a library and called in for debugging when you are experiencing problems.

Note that the example below does not work on Netscape 6.0 due to the use of the all property.

Example code:

   <HTML>

   <HEAD>

   </HEAD>

   <BODY alink=red>

   <SCRIPT>

   // An example attributes object inspector

   myAttributeObject = document.all[3].attributes.aLink;

   displayAttributes("BODY alink", myAttributeObject);

   

   // Display attributes object

   function displayAttributes(aTitle, anObject)

   {

      document.write("<H3>");

      document.write(aTitle);

      document.write("</H3>");

      document.write("<TABLE BORDER=1 CELLPADDING=2><TR>");

      document.write("<TH>Description</TH>");

      document.write("<TH>Property</TH>");

      document.write("<TH>Value</TH></TR>");

      displayTableLine("Tag attribute name:", "name", anObject.name);

      displayTableLine("Tag attribute value:", "value", anObject.value);

      displayTableLine("DOM node name:", "nodeName", anObject.nodeName);

      displayTableLine("DOM node type:", "nodeType", anObject.nodeType);

      displayTableLine("DOM node value:", "nodeValue", anObject.nodeValue);

      displayTableLine("Specified flag:", "specified", anObject.specified);

      document.write("</TABLE>");

   }

   

   // Display a table line

   function displayTableLine(aDescription, aProperty, aValue)

   {

      document.write("<TR><TH ALIGN=LEFT>");

      document.write(aDescription);

      document.write("</TH><TD>");

      document.write(aProperty);

      document.write("</TD><TD>");

      document.write(aValue);

      document.write("</TD></TR>");

   }

   </SCRIPT>

   </BODY>

   </HTML>

See also:Attr object, Attributes object, Document.createAttribute(), Element.getAttributeNode(), Element.removeAttribute(), Element.removeAttributeNode(), Element.setAttributeNode(), HasProperty(), HTML tag attribute, MutationEvent.attrChange, MutationEvent.attrName

PropertyJavaScriptJScriptNIEOperaNESECMADOMCSSHTMLNotes
name1.5 1.55.0 5.06.0 6.05.0 5.0 n/a n/a n/a1 1 n/a n/aReadOnly
nodeName1.5 1.55.0 5.06.0 6.05.0 5.0 n/a n/a n/a1 1 n/a n/a-
nodeType1.5 1.55.0 5.06.0 6.05.0 5.0 n/a n/a n/a1 1 n/a n/a-
nodeValue1.5 1.55.0 5.06.0 6.05.0 5.0 n/a n/a n/a1 1 n/a n/a-
specified1.5 1.55.0 5.06.0 6.05.0 5.0 n/a n/a n/a1 1 n/a n/aReadOnly
value1.5 1.55.0 5.06.0 6.05.0 5.0 n/a n/a n/a1 1 n/a n/a-

Inheritance chain:

Node object