I’m adding elements to a drop down using jQuery. Currently I’m adding new items using below which is working fine:
$("#treatmentGroupDropDown").append(new Option(tempGroupName, tempGroupIndex));
However I want to create and subscribe to the itemAdded event which I’ve tried using the code below, but this isn’t working:
$("#treatmentGroupDropDown").bind('itemAdded', function (event, item) { alert('item added: ' + item.toString()); });
Will something like this work?
You need some thing like this –
This will trigger the ‘itemAdded’ event after the new option has been appended, passing the option object that has just been created to the function.
Working demo – http://jsfiddle.net/ipr101/MxD25/