#TIL : Trigger event after setting val in jQuery

Jan 14, 2018 4 mins read

Trigger event after setting val in jQuery

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
comments powered by Disqus