Hello.

It is necessary to remove 3 td from each line. When clicking, you need to delete 3 rows and three columns. For example, there was a 9x9 table, with a click it became 6x6, once again a click - 3x3.

Currently, only lines are deleted. My implementation: http://jsfiddle.net/qjjsprda/4/

  • And the lines are deleted, but not 3, but half of the total number :) - MasterAlex
  • with click E - etki
  • @Etki you are fighting with windmills) - DreamChild
  • @DreamChild we all do it. - etki
  • @Etki I’ll not speak for everyone, but I can say for myself that I try to avoid fighting windmills in the field of spelling in view of the ingratitude and hopelessness of this venture - DreamChild

1 answer 1

Perhaps this option will suit you:

function add(toAdd) { var table = document.getElementById('table'); var count = table.getElementsByTagName("tr").length; for(var i = 0; i < count + toAdd; i++) { var noRowToAdd = i < count; var row = noRowToAdd ? table.rows[i] : table.insertRow(i); var low = noRowToAdd ? count : 0; var high = noRowToAdd ? toAdd: count + toAdd; for(var k = 0; k < high; k++) { var x = row.insertCell(low + k); } } } function del(toDel) { var table = document.getElementById('table'); var count = table.getElementsByTagName("tr").length; if(count - toDel < 3) return; for(var i = 0; i < toDel; i++) { table.deleteRow(count - i - 1); } var newCount = count - toDel; for(var i = 0; i < newCount; i++) { for(var k = newCount + toDel; k > newCount; k--) { table.rows[i].deleteCell(k - 1); } } } 

Example