loviji
loviji

Reputation: 13080

Remove html table rows after 2nd row

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

Upvotes: 3

Views: 3911

Answers (2)

rahul
rahul

Reputation: 187030

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.

Upvotes: 5

maček
maček

Reputation: 77778

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

Upvotes: 4

Related Questions