Availability: |
| ||||||
Inherits from: | Node object | ||||||
JavaScript syntax: | - | myAttribute = myAttributes.aPropertyName | |||||
- | myAttribute = myAttributes[anIndex] | ||||||
- | myAttribute = myAttributes[aName] | ||||||
- | myAttribute = myDocument.createAttribute(aName) | ||||||
Argument list: | aPropertyName | The name of the tag attribute | |||||
aName | An attribute name | ||||||
anIndex | A 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.
<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>
Prev | Home | Next |
Attr object | Up | Attribute.name |
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. |