How to add a new row in a table using jQuery?

Use event delegations to include both add a new and delete a table row on a web page using jQuery.

Firstly, set a button in HTML to add new row

<button id="newbtn">
   Add new Row

Now under the button click event, set the code:

$("#newbtn").click(function () {


 Live Demo

<!DOCTYPE html>
<script src=""></script>
      var x = 1;
      $("#newbtn").click(function () {
         $("table tr:first").clone().find("input").each(function () {
               'id': function (_, id) {
                  return id + x
               'name': function (_, name) {
                  return name + x
               'value': ''

      $(document).on('click', 'button.deletebtn', function () {
         return false;
<button type="button" class="deletebtn" title="Remove row">X</button>
<input type="text" id="txtTitle" name="txtTitle">
<input type="text" id="txtLink" name="txtLink">
<button id="newbtn">Add new Row</button>