HTML DOM getNamedItem() Method
The DOM getNamedItem() method in HTML is used to return the attribute node from the NamedNodeMap object.
Syntax:
namednodemap.getNamedItem( nodename )
Parameter’s Value: This method contains a single parameter nodename which is mandatory. The nodename is returned from the NamedNodeMap object.
Return Value: It returns a Node object, which represents the attribute node with the specified name
Example: In this example, we will getNamedItem() method.
HTML
<!DOCTYPE html> < html > < head > < title > DOM getNamedItem() Method </ title > < script > /* main function */ function MyBeginner() { let ele = document.getElementsByTagName("button")[0]; let item = ele.attributes.getNamedItem("onclick").value; document.getElementById("Beginner").innerHTML = item; } </ script > </ head > < body style = "text-align:center" > < h2 >DOM getNamedItem() Method</ h2 > < p > Click on the button to know the value of onclick attribute </ p > < button onclick = "MyBeginner()" > Click Here! </ button > < p id = "Beginner" ></ p > </ body > </ html > |
Output:
Supported Browsers: The browser supported by DOM getNamedItem() Method are listed below:
- Google Chrome 1
- Edge 12
- Internet Explorer 6
- Firefox 1
- Opera 12.1
- Safari 1