Javascript examples for DOM:Element getAttribute
Element getAttribute() Method - Get the value of the target attribute of an <a> element:
<!DOCTYPE html> <html> <body> <button id="myBtn" onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {// w w w. j av a2s . co m var elmnt = document.getElementById("myBtn"); var attr = elmnt.getAttributeNode("onclick").value; document.getElementById("demo").innerHTML = attr; } </script> </body> </html>