A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://webplatform.github.io/docs/dom/NamedNodeMap/getNamedItem below:

getNamedItem ยท WebPlatform Docs

getNamedItem Summary

Gets an attribute with a given name from an element.

Method of dom/NamedNodeMapdom/NamedNodeMap

Syntax
var attribute = attributes.getNamedItem();
Parameters name
Data-type
String

The name of the attribute to get.

Return Value

Returns an object of type DOM NodeDOM Node

The attribute node with the given name.

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>
<script>
function Init()
{
    var oAttrColl = document.getElementById("oElem").attributes;
    var oAttr = oAttrColl.getNamedItem("align");
    console.log("ALIGN attribute value: " + oAttr.value);
}
  </script>
 </head>
 <body onload="Init()">
  <p id="oElem" align="center">An element.</P>
 </body>
</html>

View live example

Notes

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.

Related specifications
DOM Level 3 Core
Recommendation
Attributions

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4