HTML DOM Attributes getNamedItem()
Example
Get the value of the scr attribute of an image:
const nodeMap = document.getElementById("light").attributes;
let value = nodeMap.getNamedItem("src").value;
Try it Yourself »
Get the value of the onclick attribute of a button:
const nodeMap = document.getElementById("myButton");
let value = nodeMap.getNamedItem("onclick").value;
Try it Yourself »
Description
The getNamedItem()
method returns an attribute node from a NamedNodeMap object.
Alternative:
It is easier to use the element.getAttribute() method.
See Also:
The attributes.setNamedItem() Method
Syntax
namednodemap.getNamedItem(nodename)
Parameters
Parameter | Description |
nodename | Required. The name of the node in the namedNodeMap. |
Return Value
Type | Description |
A node | The node with the specified name. |
Browser Support
attributes.getNamedItem
is a DOM Level 1 (1998) feature.
It is fully supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 9-11 |
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.