I am going to generate a table with td colspan.
for(let x = 0; x < rows; x++){
table += "<tr>";
for(let y=0; y < cols; y++){
if(x == 1 && y == 2) {
table += `<td colspan="3">${y}</td>`;
} else {
table += `<td>${y}</td>`;
}
}
table += "</tr>";
}
The problem is when I merge cells using colspan, there is an excess of columns.
https://jsfiddle.net/jL8dq1rg/
How can remove excess column (5,6) so that the columns will be even?
Note: The x & y values are dynamic so as with the colspan. Meaning, any row could have a colspan.
3
Answers
You may for example skip the columns counter when the cell spanning is encountered.
But I see in the meanwhile a similar answer was already delivered.
You could work with the "y" variable of your for-loop and add +2 to your variable whenever you add a colspan.