#TIL : Trigger event after setting val in jQuery


14 Jan 2018 / by KhanhIceTea

After setting value of an input via val method, we should call the change chaining method to trigger the onChange event of element.

$('#selectCity').change(function() {
	console.log($(this).val());
});

$('#selectCity').val('HaNoi'); // No trigger

$('#selectCity').val('HoChiMinh').change(); // Fire trigger

Sound good ?