This property yields an attributes object which is a collection of Attribute objects belonging to the object instantiated by an HTML tag.
The attributes object contains properties that JavaScript can inspect to obtain the value of HTML tag attributes for the tag that instantiated the Element object.
Structurally, the attributes object is an array whose elements correspond to properties of the Element object, each containing a name, a value and a flag. The Flag value is set true only when the property has a meaningful value. That value is reflected in the value property of the attribute object.
So, to find out all about an Element object property, you can get the value of the property by enquiring for its contents directly. However, if you use the property name to index the attributes array for that Element object, you can find out other information about that property by inspecting the attribute properties.
Access a property of an object like this:
myObject["propertyName"]
or like this:
myObject.propertyName
To access its corresponding attributes use this:
myObject.attributes["propertyName"].name
myObject.attributes["propertyName"].specified
myObject.attributes["propertyName"].value
However you should test for the existence of the myObject.attributes[myProp] object first because an attribute object is not created for every property of an Element object but only those that correspond to valid HTML tag attributes for the parent tag.
Any Element objects that represent HTML tags will have a nodeType of 1. Other node types supported by their attributes property will contain the null value.
The example code shows how this attribute access might be provided with a function.
// An attribute accessor function function getPropertyAttribute(anObject, aProp, anAttrib) { if(anObject.attributes[aProp]) { return anObject.attributes[aProp][anAttrib]; } else { return ""; } }
Prev | Home | Next |
Element.applyElement() | Up | Element.behaviorUrns[] |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |