Availability: |
| |||||
Property/method value type: | String primitive | |||||
JavaScript syntax: | - | myStyle.getAttribute(anAttribName) | ||||
- | myStyle.getAttribute(anAttribName, aCaseSense) | |||||
Argument list: | aCaseSense | A flag to indicate a case-sensitive lookup | ||||
anAttribName | An attribute of a style object |
This is an accessor method which is used to access named attributes of an Element object. Attributes are not properties in the strict sense of the word but may be accessible as if they were in some implementations.
This accessor is intended to provide a means of managing custom attributes.
You need to know the names of the attributes you want to access. If you do, then you can pass the attribute name as an argument to this method call.
The value of that attribute is returned by the method.
It would be logical to assume that attributes are named uniquely but if several share the same name, differing only in case-sensitivity, then if a case insensitive search is used you may not retrieve the one you expect. It is likely that you'll be given the last one that occurs but this may be implementation dependant.
The case-sensitive flag should be set to the Boolean true value to force a case-sensitive search and false to ignore the case of letters in the attribute name.
The following values can be passed in the optional case-sensitive flag argument:
0 - A case-insensitive search of property values is carried out by default. If several instances are located, then only the last is returned.
1 - A case-sensitive search is carried out.
2 - The value is returned exactly as was originally defined in the document source regardless of subsequent setAttribute() calls.
The result will be the value of the attribute. If the element does not have an attribute of the specified name, a null value is returned.
If a case-sensitive search is carried out using a property name stored in a variable, you should make sure that the same setting was defined for a corresponding setAttribute() call. If you don't, then it is possible that the name may have a case change if the 0 value was used in the setAttribute() call. After that case change, the value in the variable will no longer match the property defined for the receiving object.
See also: | Element.getAttribute(), style.setAttribute() |
Prev | Home | Next |
style.fontWeight | Up | style.getExpression() |
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. |