Export (0) Print
Expand All
go
Expand Minimize

getNamedItem method

Gets an attribute specified with the name property, by using the attributes collection.

Document Object Model (DOM) Level 3 Core Specification, Section 1.4

Syntax

var retval = attributes.getNamedItem(bstrName);

Parameters

bstrName [in]

Type: BSTR

A String that specifies the name of the attribute to get.

Return value

Type: IHTMLDOMAttribute

Returns an attribute with the specified name.

Standards information

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.

Windows Internet Explorer 8 and later. In IE8 Standards mode, the getNamedItem method does not create Attr objects that do not exist in the collection; it returns null when an attribute is not found. For more information on IE8 mode, see Defining Document Compatibility.

getNamedItem was introduced in Microsoft Internet Explorer 6.

Examples

The following example shows how to use the getNamedItem method to retrieve the value of an attribute.

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/getNamedItemEx1.htm


<!DOCTYPE html>
<html>

<head>
  <title>getNamedItem Example</title>
</head>

<body>
  <h1>getNamedItem Method Example</h1>
  <p id="oElem">An element with the <strong>id</strong> attribute set to <strong>oElem</strong>.</p>
  <script>
    var oAttrColl = oElem.attributes;
    var oAttr = oAttrColl.getNamedItem("id");
    alert("ID Attribute value: " + oAttr.value);
  </script>
</body>

</html>

See also

attributes

 

 

Show:
© 2014 Microsoft