javascript – Delete all rows except last row in a table JQUERY-ThrowExceptions

Exception or error:

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.

How to solve:

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()

Leave a Reply

Your email address will not be published. Required fields are marked *