0

I insert new row by clone of one of the rows, but I noticed that it does not respond to events like (click, change)

I used this code, but unfortunately it doesn't add events to it:

      
      
$('#input1 ,#newid').change(function () {

        console.log('here');

    })

    function copy()
    {

        var $LastRow = $('#table tbody tr:last').clone(true);

        var $inputs = $LastRow.find('td').children();

        $inputs.attr('id', 'newid');

        var Table = $('#table tbody');

        Table.append($LastRow);

    }
<table id="table">
    <tr>
        <td>
            <input id="input1" />
        </td>
    </tr>
</table>

<button onclick="copy()"> ok</button>

 
          <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  • Remove the `id` attributes in the HTML of the repeated content. Change them to classes instead. Then use delegated event handlers, as the answer @DBS linked to suggests – Rory McCrossan Jul 13 '21 at 12:41

0 Answers0