#til

#TIL : 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

Enjoyed this post?

If you found this helpful, consider sharing it or leaving a kudo!

0 kudos