Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I detect a jQuery trigger events completion?

I'm trying to trigger a second event dependent on the first like so:

...
$('#productFamilyId').val(data.contents.productfamily);
$('#productFamilyId').trigger('change', function() {
    $('#productId').val(data.contents.product);
    $('#productId').trigger('change');
});

It's not waiting for the first trigger to complete before attempting to trigger the second event. Is it possible to wait for the first trigger to complete?

like image 755
user1216398 Avatar asked Jul 19 '12 15:07

user1216398


1 Answers

Probably you want this:

$('#productFamilyId').trigger('change', function() {
   $('#productId').val(data.contents.product);
   setTimeout(function(){ 
      $('#productId').trigger('change'); 
   },1);
});
like image 183
Engineer Avatar answered Nov 01 '22 12:11

Engineer