0

I want to get existing function, setted in element as listener. Is it possible?

for example:

button.onclick = function() { console.log("clicked") } // setted by another library

console.log(button.someMethod()) // function() { console.log('clicked') }
Majid Ainizoda
  • 89
  • 1
  • 12
  • Does this answer your question? [How to find event listeners on a DOM node in JavaScript or in debugging?](https://stackoverflow.com/questions/446892/how-to-find-event-listeners-on-a-dom-node-in-javascript-or-in-debugging) – Simone Rossaini Feb 03 '22 at 12:41
  • In this particular case you can do `console.log(button.onclick);`. If the event listener is attached using `addEventListener`, there's no way to access the attached listener programmatically. – Teemu Feb 03 '22 at 12:42
  • @Teemu Listener setted by slick.js. – Majid Ainizoda Feb 03 '22 at 12:45
  • I didn't notice the jQuery tag earlier. If an event is attached by jQuery, then you might find your answer from Crescent Fresh's answer in the dup suggestion Simone has linked above. Though the post is really old, I'm not sure if any of those is still valid. – Teemu Feb 03 '22 at 12:52

0 Answers0