Delete html table rows after second row

how to delete html table rows after second row? if the table has 5 rows, 1 and 2 are safe, 3,4,5 should be deleted

+3
source share
2 answers

Use disconnect ( ) instead of delete ()

var myremovedElems = $("#table tr:gt(1)").detach();

The .detach () method is the same as .remove (), except that .detach () saves all jQuery data associated with deleted items. This method is useful when deleted items need to be reinserted at the DOM time.

+5
source

$("#table tr:gt(1)").remove();

+4
source

Source: https://habr.com/ru/post/1735565/


All Articles