I am new to javascript and am currently trying to loop through table rows to get the data from it however its showing an error that it can't recognize rows
for table
.
<div class="row" id="tablediv">
<div class="col">
<table class="table table-striped table-bordered" id="table"/>
</div>
</div>
var table = document.getElementById('#table');
for (let i in table.rows) {
let row = table.rows[i];
//iterate through rows
//rows would be accessed using the "row" variable assigned in the for loop
console.log(row);
for (let j in row.cells) {
let col = row.cells[j];
//iterate through columns
//columns would be accessed using the "col" variable assigned in the for loop
console.log(col);
}
}
offices:1048 Uncaught TypeError: Cannot read properties of null (reading 'rows')
at save (offices:1048:25)
at HTMLButtonElement.onclick (offices:101:84)
Am I doing something wrong or is there a workaround for that?