Element getAttribute() Method - Get the value of the onclick event attribute of a <button> element: - Javascript DOM

Javascript examples for DOM:Element getAttribute

Description

Element getAttribute() Method - Get the value of the onclick event attribute of a <button> element:

Demo Code

ResultView the demo in separate window

<!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>

Related Tutorials