HTML DOM getNamedItem()Method

属性对象参考手册Attribute Object

Examples

Returns the value of the button element's onclick attribute:

var btn=document.getElementsByTagName("BUTTON")[0];
btn.attributes.getNamedItem("onclick").textContent;

Output:

myfunction()

Try it Yourself »

Definition and Usage

The getNamedItem() method returns the value of the specified attribute name from the node list.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the getNamedItem() method.

Note:Internet Explorer 8 and earlier IE versions do not support this method.


Syntax

namednodemap.getNamedItem(name)

Parameters

Parameters Type Description
nodename String Required. The name of the node you want to return from the node list.

Return Value

Type Description
Node object The node with the specified name.

Technical Details

DOM Version Core Level 1


属性对象参考手册Attribute Object

Other Extensions