Search code examples
jqueryonchange

Onchange input event isn't fired on jquery


I'm working with jquery.

And i have text input in a form, i would like to process the change event.

$("#my_input").change(function(){alert('123');});

the event is fired normally when i edit the field manually, but when i change the field's value with a script (sometimes with an external script) it doesn't work.

is there any solution ?

and thanks in advance.


Solution

  • The change event is not designed to detect programmatic changes. You can trigger the event manually when setting the value, though:

    $('#my_input').trigger('change');
    

    shortcut:

    $('#my_input').change();