How can I attach two different callbacks to one jQuery UI widget?

50 Views Asked by At

With custom jQuery Ui widget, you can attach your own callback functions to it by passing options to the plugin. However, if I want to attach one callback to "generate_img" event and later on another different but not mutually exclusive behaviour to the same widget event "generate_img", the later one will replace, instead of adding to the existing behaviour.

Is there a way to solve this problem? Thanks.

1

There are 1 best solutions below

1
GertG On

You could do something like this (using a dialog Widget and the beforeClose event as an example):

function one(){alert("one");}
function two(){alert("two");}

$( function() {
    $( "#dialog" ).dialog(
        {beforeClose: one}      
    );

    var original = $( "#dialog" ).dialog("option", "beforeClose");
    $( "#dialog" ).dialog("option", "beforeClose", function(){
        original();
        two();
    });    
});