Search code examples
javascriptjqueryonchangejquery-events

jQuery change event after setting value via document.getElementById(...).value


I'm trying to handle change event, but it seems it doesn't work. I would like to handle the event using jQuery after setting value via document.getElementById('id_of_input').value. Here is the code: http://jsbin.com/axagej (to edit see: http://jsbin.com/axagej/edit) - I would like to see an alert.


Solution

  • If you're setting the value programatically you need to fire the event yourself using change or trigger:

    $("#sample").change();
    

    or

    $("#sample").trigger("change");