What is the easiest and best way to trigger change event when setting the value of select element.
I've expected that executing the following code
$('select#some').val(10);
or
$('select#some').attr('value', 10);
would result in triggering the change event, which i think is pretty logic thing to be done. Right?
Well, it isn't the case. You need to triger change() event by doing this
$('select#some').val(10).change();
or
$('select#some').val(10).trigger('change');
but i'm looking for some solution which would trigger change event as soon as select's value is changed by some javascript code.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…