HTML DOM Attributes getNamedItem() Method
- Previous page getNamedItem()
- Next page isId
- Go back to the previous level HTML DOM Attributes
Definition and usage
getNamedItem()
Method returns the attribute node with the specified name from namedNodeMap.
Alternative
Use element.getAttribute() method Easier.
See also:
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;
Example 2
Get the value of the onclick attribute of the button:
const nodeMap = document.getElementById("myButton"); let value = nodeMap.getNamedItem("onclick").value;
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 |
- Previous page getNamedItem()
- Next page isId
- Go back to the previous level HTML DOM Attributes