I need to get the value of a td and place it in the array as in the following example:
function finalizaCompra() {
var tbl = document.getElementById("tblItens");
var produto = [];
if (tbl != null) {
for (var i = 0; i < tbl.rows.length; i++) {
for (var j = 0; j < tbl.rows[i].cells.length; j++)
produto[j] = tbl.rows[i].cells[j];
console.log(produto[j]);
}
}
}
<table id="tblItens">
<tr>
<td> 1 </td>
<td> 2 </td>
</tr>
</table>
<img src = "http://img.freepik.com/icones-gratis/carrinho-de-compras-lado-vazio-vista_318-50806.jpg?size=338&ext=jpg" onclick="finalizaCompra()" width="100" height="100" />
But returns as undefined, can you help me?