I'm binding a dropdown
("#dropdownlist").change(function(){
//Do stuff
});
The above code gets called many times.
How can I unbind this event before binding it each time?
I'm binding a dropdown
("#dropdownlist").change(function(){
//Do stuff
});
The above code gets called many times.
How can I unbind this event before binding it each time?
Use following logic:
var f = function () {
}
$('#xx').bind('change', f); // for bind function f
$('#xx').unbind('change', f); // for unbind unbind function f
Additionally jQuery supports namespaces.
For example say you have change handlers that do validation and change handlers that do help text hovering.
You could register:
$("#foo").bind("change.validation", doValidation() );
and
$("#foo").bind("change.helptext", toggleHelptext() );
and then you can unbind a specific set before re-adding validation, e.g.
$("#foo").unbind("change.validation");
$("#foo").bind("change.validation", doValidation() );
HTH Alex