getNamedItem Method | Internet Development Index |
Retrieves an attribute specified with the name property using the attributes collection.
Syntax
oGetName = attributes.getNamedItem(sGetName)
Parameters
sGetName Required. String that specifies the name of the attribute to retrieve.
Return Value
Returns an attribute with the specified name.
Remarks
If the attribute applies to an element but is not specified, this method returns the attribute with the specified name set to an empty string.
If the attribute does not apply to the element and is not specified, then an error is returned.
If the attribute does not apply to the element and is specified, then the attribute with the specified name is returned.
Example
The following example shows how to use the getNamedItem method to retrieve the value of an attribute.
<HTML> <HEAD> <SCRIPT> function Init() { var oAttrColl = oElem.attributes; var oAttr = oAttrColl.getNamedItem("align"); alert("ALIGN attribute value: " + oAttr.value); } </SCRIPT> </HEAD> <BODY ONLOAD="Init()"> <P ID="oElem" ALIGN="center">An element.</P> </BODY> </HTML>
Standards Information
This method is defined in World Wide Web Consortium (W3C) Document Object Model (DOM) Level 1 .
Applies To
attributes