I have this code...
// Display number of pixels left from nav width
$('.inputs input').live('keyup',function() {
var nav_width = $('#nav-width').val();
var sumOfVals = 0;
$('.inputs input').each(function () {
sumOfVals = sumOfVals + parseInt($(this).val());
});
sumOfVals = nav_width - sumOfVals;
$('#px-left em').html(sumOfVals);
});
It needs to be executed on the keyup event of dynamically added input fields but I want to use the 'on' event. Is this possible? I have tried replacing 'live' with 'on' but it didn't work.
You can't just replace
livewithon. If you read the docs aboutonyou'll see this:So by following that you'd use
onlike this:.closest-parentis the closest parent element to.inputs. By using the closest parent instead of justdocumentyou improve performance.