I am wondering how can I check if the button has on-click listener. My webpage has a button, but sometimes clicking the button has no effect.I am wondering if I can check if the click handler is attached.
I tried this, but it doesn't work..
$('#changeStatus').onClick()
It depends on how the listener was applied....
If the listener was set up on the event property, you can check the property:
let input = document.querySelector("input");
input.onclick = function(){ console.log("I was clicked"); }
if(input.onclick){
console.log("There is a click event listener.");
} else {
console.log("There is NO click event listener.");
}
if(input.onkeydown){
console.log("There is a keydown event listener.");
} else {
console.log("There is NO keydown event listener.");
}
<input>
But, if the listener is registered using the modern DOM API of .addEventListener(), then no, there is no way to know.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With