To get table row value in JavaScript, use
querySelector
to get td
value by row and column indexes.So if this is your table
:
<table id="my-table">
<tbody>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
</tbody>
</table>
Then you can get the value of, say, td
, that holds 8
with this JavaScript:
const cell = document.querySelector('#my-table tr:nth-child(3) td:nth-child(2)');
console.log(cell.textContent); // 8