$(function() {
$('table td').click(function(e) {
if (e.target.id === "Sellbtn") {
var sell = prompt("Enter the amount you wish to sell");
//problem is here i guess
$(this).parent('tr').cells[4].innerHTML = parseInt($(this).parent('tr').cells[4].innerHTML) - sell;
} else if (e.target.id === "Deletebtn") {
return false;
} else {
var ask = prompt("Input");
$(this).html(ask);
}
});
});
I have a table with several rows each row has two buttons (Sell and Delete). What i want is when I click on the sell button of a row it gets me the prompt and then the amount entered should get subtracted from the number in cell[4] of that ROW and change the amount in cell[4] to this new amount. This doesn't work obviously so what should i do? And by the way this code gives me the error: Cannot read property '4' of undefined.
.cellscomes from?cellsproperty is not standard jQuery. Are you getting that from a plugin? The way I would recommend getting a particular table cell is:$(this).parent().children('td').eq(4).text(). (There's no need to filter the parent -- there's only one.)