How to refuse a callback for an event?

In JavaScript, we can add several functions to the onload body or the onclick button. Is it possible to delete one of them if we have a link to a function?

If possible, how to do the same in jQuery as well as in regular JavaScript?

+4
source share
1 answer

Yes, but it depends on how the handler was bound in the first place.

If you used addEventListener , you can cancel the use of removeEventListener .

If you used jQuery, you can use .unbind() .

If you used attachEvent , you can use detachEvent() .

If you used onclick or other onxxx functions, you can remove them by setting null , f.ex elem.onclick = null .

+6
source

All Articles