strange $('select').trigger('change') behaviour
Somewhere in my javascripts I usually set the value of a select and fire
the change event manually. But there is the following issue I do not
really understand:
I've the following code, which seems to not fire the change event of the
select properly.
$('select#select_location_address').val(iAddressId);
$('select#select_location_address').trigger('change');
but the following works
$('select#select_location_address').val(iAddressId);
setTimeout(function(){
$('select#select_location_address').trigger('change'); }, 1);
Can somebody explain why the explicit call right after setting the value
of the select does not fire the change event, but using timeout does?
Or is there a better solution to get the change event fired when setting
its value via jQuery?
No comments:
Post a Comment