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

Spread the love

Question Description

The logic in the change() event handler is not being run when the value is set by val(), but it does run when user selects a value with their mouse. Why is this?




Practice As Follows

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

Do this instead:

$("#single").val("Single2").change();

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.