Reputation: 151
I'm new to jquery so please bear with me.
I have a table that has columns quantity, price, and amount. The amount column should be updated whenever there are changes in either quantity or price.
So far, here's my jquery event:
$('input.qtyPrice').on('change',function() {
var rowIndex = $(this).parent().parent().index();
console.log($('#tableItems tr').eq(rowIndex).find('td').eq(4));
})
This writes the console [prevObject: o.fn.init[0], context: document, jquery: "2.1.0", constructor: function, selector: ""…]context: documentlength: 0prevObject: o.fn.init[0]__proto__: o[0]
I took that answer from another question here in Stackoverflow.
My problem is, I can't seem to access the INPUT element (amount) inside the TD.
Sorry for my English. I appreciate your inputs. Thank you.
Upvotes: 0
Views: 2003
Reputation: 388416
You don't have to access the rowIndex, you can directly find the amount like
$('input.qtyPrice').on('change', function () {
var $tr = $(this).closest('tr');
$tr.find('td:nth-child(5) input').val('updated')
})
Upvotes: 1