Hack Dawg
Hack Dawg

Reputation: 108

Delete all rows except last row in a table JQUERY

Could it be possible?

I tried:

$("#tbl1 tbody").empty().append(markup)
var tbl = document.getElementById("tbl1")
var lastRow = tbl.rows[tbl.rows.length - 1];
$("#tbl2 tbody").append(lastRow)

Thanks for any help.

Upvotes: 0

Views: 819

Answers (1)

Ronak Lalwani
Ronak Lalwani

Reputation: 386

It's easy all you have to do is check if it's not the last row then remove. Refer below-mentioned code to remove every row except last.

$("table tr:not(:last)").remove()

Upvotes: 3

Related Questions