Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove html table rows after 2nd row

Tags:

jquery

how remove html table rows after 2nd row? if in table have 5 row, 1 and 2 are safe, 3,4,5 must be remove

like image 486
loviji Avatar asked Aug 16 '26 10:08

loviji


2 Answers

Use detach() instead of remove()

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

The .detach() method is the same as .remove(), except that .detach() keeps all jQuery data associated with the removed elements. This method is useful when removed elements are to be reinserted into the DOM at a later time.

like image 122
rahul Avatar answered Aug 19 '26 22:08

rahul


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

like image 31
maček Avatar answered Aug 19 '26 23:08

maček