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
live
withon
. If you read the docs abouton
you'll see this:So by following that you'd use
on
like this:.closest-parent
is the closest parent element to.inputs
. By using the closest parent instead of justdocument
you improve performance.