Delete all rows in an HTML table

后端 未结 19 1794
既然无缘
既然无缘 2020-12-04 12:03

How can I delete all rows of an HTML table except the \'s using Javascript, and without looping through all the rows in the table? I have a very huge

19条回答
  •  盖世英雄少女心
    2020-12-04 12:19

    this is a simple code I just wrote to solve this, without removing the header row (first one).

    var Tbl = document.getElementById('tblId');
    while(Tbl.childNodes.length>2){Tbl.removeChild(Tbl.lastChild);}
    

    Hope it works for you!!.

提交回复
热议问题