Eric Belair Eric Belair - 1 year ago 80
jQuery Question

Why does the jquery change event not trigger when I set the value of a select using val()?

The logic in the

event handler is not being run when the value is set by
, but it does run when user selects a value with their mouse. Why is this?

<select id="single">

$(function() {
$(":input#single").change(function() {
/* Logic here does not execute when val() is used */


Answer Source

Because the change event requires an actual browser event initiated by the user instead of via javascript code.

Do this instead:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download