How to disable event handlers that were linked through jQuery without using jQuery

Let's say I have the following jQuery:

$('#myelement').bind('click', foo);

How can I cancel this event without using jQuery?

The event does not appear in any of these methods in the DOM element:

var domElement = document.getElementById('myelement');
domElement.onclick // == null
domElement.click // == undefined

So how can I unlock it without using jQuery, for example the following:

$('#myelement').unbind()
+3
source share
1 answer

If you are using the latest jQuery, this will work:

delete $.cache[document.getElementById("myelement")[$.expando]].events.click;

You can test it here .

Please note that this is not a complete cleanup; you can use jQuery . removeEvent () for this if you want to clear all handlers.

+2

Source: https://habr.com/ru/post/1768791/


All Articles