Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery event for when <option>s are added or removed from a <select>

Is there a jquery event for when options are added or removed from a select control on an HTML page? I have tried .change() but it only seems to fire when I click on option elements. I.e. this doesn't work:

$(function() {
    $('#select').change(function() {
            alert('hello world');
    })
});

Thank you :).

like image 367
ale Avatar asked Nov 14 '11 16:11

ale


1 Answers

When adding a new element to an existing dropdown, you should do a: $("#selector").trigger ("change"); to get the behaviour you want.

like image 140
Sage Avatar answered Oct 12 '22 10:10

Sage