jQuery 1.7.2 -- trying to convert bound events to delegation, but having trouble.
This code is working:
- $(document).ready(function()
- {
- $(".itemLabel").change(function() {
- var theLabel = this.value;
- var railsRoute = $(this).data('route');
- $.post(railsRoute, {_method: "put", label: theLabel} );
- });
- });
However, this does not. Actually, it works identical to the code above in that it works for all existing .itemLabel elements, but not for any new ones added the page is originally rendered.
- $(document).ready(function()
- {
- $('.itemPortal').on('change', '.itemLabel', function(event) {
- var theLabel = this.value;
- var railsRoute = $(this).data('route');
- $.post(railsRoute, {_method: 'put', label: theLabel} );
- });
- });
It's my understanding that .on() is preferred over .delegate() as of 1.7, but clearly I'm still doing something incorrectly.
Any suggestions as to what I'm missing? Thanks.