I don’t understand why but .parent() is not working on dynamically created elements.
Here is fiddle displaying my problem. It calculates discount price on static element, not so much on created one.
$('.item-sizes .discount-percent').live('keydown', function () {
var percentValue = $(this).val();
var basePrice = $('.base-price', $(this).parent().parent()).val(); // Undefine on live elements, defined on static
if (basePrice) {
discountValue = basePrice - ((percentValue / 100) * basePrice);
$('.discount-price', $(this).parent().parent()).val(discountValue);
}
});
You have the
base-priceclass on the wrong element:which explains the
NaNresponsehere it is fixed:
http://jsfiddle.net/znvHa/5/