0

I have set a click handler on button1, when the click handler is called it prints the id of the button and the value of "onclick" based on e.currentTarget. The callback is called corrrectly, the id is correct, BUT the "onclick" value has a value of "undefined" not something that represents the function that is called in practice (actually the value is "null" when I check in the chrome debugger). My question is 1) Why is e.currentTarget.onclick null ? 2) Where can I see if an onclick function is defined and wht it's value is ? Thanks

<body>
     <div id="top1"><button id="but1"> button 1</button></div>
</body>


function call_cb_click(text) {
    return function foo(e) {
        console.log("in callback for "+ text + "cb is " + e.currentTarget.onClick);
    }
}
function test() {
    $("#but1").on('click',call_cb_click("button 1 "));  
}
$(document).ready(test);

1 Answers1

0

You didn't set an onclick function to your DOM element. It's either done with an attribute in your HTML or by using the DOM API as you did: myElement.onClick = myFunction;

Here you simply added an eventListener via jQuery. You can probably use this to get the jQuery events or use Developper tools to get the event listeners

Axnyff
  • 9,213
  • 4
  • 33
  • 37
  • The answer to my question is that the onclick event refers to DOM event handlers and not to handlers set by jQuery. The link given by Axnyyff indicates that there is no official way to check if handlers have been set by jQuery - just back doors that may change. – Yonatan.Lehman Jul 24 '17 at 18:06