Collapse the table of content
Expand the table of content

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



var retval = attributes.getNamedItem(bstrName);


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


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.

getNamedItem was introduced in a Windows Store app using JavaScript.


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

<!DOCTYPE html>

  <title>getNamedItem Example</title>

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


See also




© 2016 Microsoft