Get the value of the onclick attribute node of a <button> element:
Click the button to display the value of the onclick attribute node of the button element.
<!DOCTYPE html> <html> <body> <button id="myBtn" onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {//from w ww. j a va 2 s . c om var elmnt = document.getElementById("myBtn"); var attr = elmnt.getAttributeNode("onclick").value; document.getElementById("demo").innerHTML = attr; } </script> </body> </html>