简体   繁体   中英

Get event of dropdown change value in jQuery

I want to get the event whenever my dropdown change its value

currently i'm using:

$('#dropdown').on('change', function() {
    // doing some process here
}

but what I want is to get the event even when changing the value of the dropdown through jQuery. Lets say I do something like this:

$('#dropdown').val( someValue );

I also want to catch the code above on the change event.

Is there a way for jQuery to get this event?

if you change the value via jQuery, you can trigger the change event on that element with:

$('#dropdown').val( someValue ).change();

or

$('#dropdown').val( someValue ).trigger('change');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM