To limit the query by id to the item tree, you can use querySelector
:
document.getElementById('table1').querySelector('#cell1');
But it's just superfluous when you can just do
document.getElementById('cell1');
Change To better respond to an OP query, you can access the table cells sequentially as follows:
document.getElementById('table1').tBodies[i].rows[j].cells[k];
Here, the k
cell of the j
row of the i
th table body is selected. If your table has only one <tbody>
element (for example, a regular one) or you want to access the cells separately from their <tbody>
, you can omit the .tBodies[i]
.
source share