Let's say you have a simple Text Box and button on your page. Clicking on the button will update the textbox value:
HTML:
<input type="text" id="myText" val="" />
<input type="button" id="myBtn" value="Change TextBox Value" />
jQuery:
$("#myBtn").on('click', function() {
$("#myText").val('adsf');
})
I'd like to add an event listener for the change event of the textbox, like so:
$('#myText').on('change', function(){
alert('Changed!')
});
That alert does not get triggered when you click the button but it does get triggered when you manually change the textbox value and focus out of it.
I know you can add $("#myText").trigger('change')
to the onclick event of the button, but I wish to only accomplish this by adding an event listener to the textbox.
Thanks