JQuery add remove tr in table 2016-07-13 06:31

In this page I will show you how to use JQuery remove and add tr element in table. Copy the code following and click remove or add button. If you do not want remove the first tr element or add after last tr element just change the JQuery selector.

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <title>Remove tr in table</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.3/jquery.min.js"></script>
        $(document).ready(function () {
            $("#remove").click(function () {
                $("table tr:first").remove();
            $("#add").click(function () {
                $("table tr:last").after("<tr><td>New One</td><td>21</td><td>Guangzhou</td></tr>");
<button id="remove">Remove first tr element</button>
<button id="add">Add tr element after last one</button>