Gets an attribute with a given name from an element.
Method of dom/NamedNodeMapdom/NamedNodeMap
Syntaxvar attribute = attributes.getNamedItem();
Parameters name
The name of the attribute to get.
Return ValueReturns an object of type DOM NodeDOM Node
The attribute node with the given name.
ExamplesThe 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>
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 specificationsMozilla Developer Network : [getNamedItem Article]
Microsoft Developer Network: [getNamedItem Method Article]
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