Jquery: how to remove .click () handler setting?

I found that sometimes I connect 2 functions to buttun using .click (function () {}), is it possible to delete the previous attached function before I connect a new one?

+4
source share
3 answers

Do not use an anonymous delegate. However, you can .unbind a named function.

UPDATE

In fact, you can call .unbind () with no arguments to remove all handlers, or .unbind ('click') to remove all handlers for a specific event.

+8
source

jQuery has unbind ()

+2
source

There are two ways:

function foo(){ //do stuff } function bar(){ //do more } jQ.click(foo).click(bar); jQ.unbind(foo); 

or

 jQ.bind('click.foo', function(){ //do stuff }); jQ.click(function(){ //do more }); jQ.unbind('.foo'); 
0
source

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


All Articles