How to unleash an event

I anchor a drop down list

("#dropdownlist").change(function(){
    //Do stuff
});

The above code is called many times.

How can I cancel this event before binding it every time?

+3
source share
4 answers

You can use the method unbind():

$('#dropdownlist').unbind('change');
+8
source

You can use one instead of bind:

("#dropdownlist").one('change',function(){});
+7
source

:

var f = function () {

}

$('#xx').bind('change', f); // for bind function f
$('#xx').unbind('change', f); // for unbind unbind function f
+2

, jQuery .

, , , .

:

$("#foo").bind("change.validation", doValidation() );

$("#foo").bind("change.helptext", toggleHelptext() );

, .

$("#foo").unbind("change.validation");
$("#foo").bind("change.validation", doValidation() );

Alex

+2

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


All Articles