Javascript DOM HTML NamedNodeMap getNamedItem() Method

Introduction

Get the value of the onclick attribute of a button element:

Click the button to get the value of the onclick attribute of the button element.

View in separate window

<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Test</button>
<p id="demo"></p>

<script>
function myFunction() {//from  www . ja va2s . c  o m
  var a = document.getElementsByTagName("BUTTON")[0];
  var x = a.attributes.getNamedItem("onclick").value;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The getNamedItem() method returns the attribute node with the specified name from a NamedNodeMap object.

element.getNamedItem(nodename);

Parameter Values

Parameter Type Description
nodename String Required. The name of the node in the namedNodeMap you want to return

The getNamedItem() method returns a Node object representing the attribute node with the specified name.




PreviousNext

Related