<!DOCTYPE html>
<html>
<body>

<p>Click the button to find out if the button element has an onclick attribute.</p>

<button id="myBtn" onclick="myFunction()">Try it</button>

<p>Internet Explorer 8 and earlier does not support the hasAttribute() method.</p>

<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("myBtn").hasAttribute("onclick");
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>