HTML DOM Attributes getNamedItem() Method

Definition and usage

getNamedItem() Method returns the attribute node with the specified name from namedNodeMap.

Alternative

Use element.getAttribute() method Easier.

See also:

attribute.value property

attribute.name property

attributes.setNamedItem() method

element.getAttribute() method

element.getAttributeNode() method

Example

Example 1

Get the value of the scr attribute of the image:

const nodeMap = document.getElementById("light").attributes;
let value = nodeMap.getNamedItem("src").value;

Try it yourself

Example 2

Get the value of the onclick attribute of the button:

const nodeMap = document.getElementById("myButton");
let value = nodeMap.getNamedItem("onclick").value;

Try it yourself

Syntax

namednodemap.getNamedItem(nodename)

Parameter

Parameter Description
nodename Required. The name of the node in namedNodeMap.

Return value

Type Description
Node Node with the specified name.

Browser support

attributes.getNamedItem It is a DOM Level 1 (1998) feature.

All browsers support it:

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
Supported 9-11 Supported Supported Supported Supported