My application has dynamically added Dropdowns. The user can add as many as they need to.
I was traditionally using jQuery's live()
method to detect when one of these Dropdowns was change()
ed:
$('select[name^="income_type_"]').live('change', function() {
alert($(this).val());
});
As of jQuery 1.7, I've updated this to:
$('select[name^="income_type_"]').on('change', function() {
alert($(this).val());
});
Looking at the Docs, that should be perfectly valid (right?) - but the event handler never fires. Of course, I've confirmed jQuery 1.7 is loaded and running, etc. There are no errors in the error log.
What am I doing wrong? Thanks!
live
is actually usingon
anyway, so a re-write of legacy code might not be needed just yet untillive
will be removed, which I believe is 1.9. Excerpt from 1.7.1 source:live: function( types, data, fn ) {jQuery( this.context ).on( types, this.selector, data, fn ); return this;}
So if one is not upgrading to a version in whichlive
is gone an update may not be needed right away for legacy code. For new code off course usingon()
instead is as recommended. I just thought this information might help someone else at some stage. – Cyclolive
toon
. – Coactive