Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
delete rows dynamically using jquery problem. The new buttons don't delete the new rows

I am working on creating a table that I can add and delete rows from it dynamically using JQuery. My problem is that the only delete button that works fine is the first one ( the one with the first default row) later on whenever I add new rows the delete buttons for them doesn't remove the row. These are parts of my code. I will appreciate your help!

 <script>
            $(document).ready(function(){

                $("#add").click(function(){
                    var id="<input type='text' placeholder='Enter student id'>";
                    var name = "<input type='text' placeholder='Enter student name'>";
                    var timeSlot="<input type='text' placeholder='The time slot'>";

                    var row = "<tr> <td>"+id+"</td>" +
                         "<td>"+name+"</td>" + 
                         "<td>"+timeSlot+"</td>"+
                         " <td> <button class='remove' type='submit'>Remove Row</button> </td> </tr>";

                    $("tbody").append(row);
                });

                $("button.remove").click(function(){
                   $(this).parents("tr").remove();
                });
            });
        </script>
<table id="myTble">
            <thead>
                <tr>
                    <th>Student id</th>
                    <th>Student name</th>
                    <th>TimeSlot</th>
                    <th> <button id="add" type="submit">Add Row</button> </th>
                </tr>
            </thead>
              
            <tbody>
                <tr> 
                    <td>00000000</td>
                    <td>xxx xxxxx</td>
                    <td>9:00-10:00</td>
                    <td> <button class="remove" type="submit">Remove Row</button> </td>
                </tr>
            </tbody>

        </table>

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!