Javascript examples for DOM:Element getAttribute
Element getAttribute() Method - Get the value of the onclick event attribute of a <button> element:
<!DOCTYPE html> <html> <body> <button id="myBtn" onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {//from w w w . j a v a2 s .c om var x = document.getElementById("myBtn").getAttribute("onclick"); document.getElementById("demo").innerHTML = x; } </script> </body> </html>