$('.update').live('click', function() { $(this).button('loading'); $('#listInserts tr').remove(); updatelist(); $(this).button('reset'); $(this).button('complete'); }); 

The question is how to make $(this).button('reset'); and $(this).button('complete'); executed after the updatelist(); function is processed updatelist(); , but not immediately?

    1 answer 1

    get a Kolbek:

     function updatelist(callback) { ... // update list ... callback(); } 

    and pass it to the function:

     $('.update').live('click', function() { $(this).button('loading'); $('#listInserts tr').remove(); var that = this; // это не самый лучший способ сохранения контекста updatelist(function(){ // <= callback $(that).button('reset'); $(that).button('complete'); }); }); 

    if asynchronous functions are called in the updatelist , then pass a callback to methods such as .success or .error that asynchronous functions may have