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: String

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.

Examples

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


<!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");
    console.log("ID Attribute value: " + oAttr.value);
  </script>
</body>

</html>

See also

attributes

 

 

Show:
© 2014 Microsoft