Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6529201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:36:31+00:00 2026-05-25T09:36:31+00:00

I am trying to add another row in a table(that contains form inputs) when

  • 0

I am trying to add another row in a table(that contains form inputs) when the add button is clicked.

Here is my code:

$("#add_ingr").click(function(){
    var row = '<tr>'
                   +'<td>' 
                      +'<?php $data = array('name' => 'ingr_name[]', 'class' => 'ingr_name'); echo form_input($data); ?>'
                   +'</td>'
                   +'<td>'  
                      +'<?php $data = array('name' => 'ingr_amount[]', 'class' => 'amt'); echo form_input($data); ?>'
                   +'</td>'
                   +'<td>'
                      +'<?php $data = array('name' => 'ingr_unit[]', 'class' => 'unit'); echo form_input($data); ?>'
                      +'<span class="remove">X</span>'+'</td>';                                                             
              +'</tr>';

   $("#ingr_table > tbody").append(row);

});

Whenever I would click the element with an ID of add_ingr, a new row would successfully be appended on the table but whenever I would click the x text which has the class of remove, this code never gets executed:

$("span.remove").click(function() {
alert('clicked');
    $(this).parent().remove();
});

I don’t know what was wrong with it and I’ve been trying to find a solution for my problem but unfortunately, I can’t have things working.

Can somebody tell me what’s wrong with this? I would really appreciate your help. Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T09:36:31+00:00Added an answer on May 25, 2026 at 9:36 am

    The click handler is not being bound to the element. Either change your code to:

    $("span.remove").live('click', function() {
        alert('clicked');
        $(this).closest('tr').remove();
    });
    

    so that it span.remove is always bound, or place the bind inside of your other click function:

    $("#add_ingr").click(function(){
        var row = $('<tr>'
                       +'<td>' 
                          +'<?php $data = array('name' => 'ingr_name[]', 'class' => 'ingr_name'); echo form_input($data); ?>'
                       +'</td>'
                       +'<td>'  
                          +'<?php $data = array('name' => 'ingr_amount[]', 'class' => 'amt'); echo form_input($data); ?>'
                       +'</td>'
                       +'<td>'
                          +'<?php $data = array('name' => 'ingr_unit[]', 'class' => 'unit'); echo form_input($data); ?>'
                          +'<span class="remove">X</span>'+'</td>';                                                             
                  +'</tr>');
    
       $("#ingr_table > tbody").append(row);
       row.find('span.remove').click(function() {
         alert('clicked');
         $(this).closest('tr').remove();
       });
     });
    });
    

    Also, .parent() will select the <td> element, so I changed this to .closest('tr') which will select the closest table row.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to update a table in my database with another row from
I'm trying to insert another table row into a table after calling from a
I'm trying to add a row to an InnoDB table with a simply query:
Greetings everyone- In my code below I'm trying to add a Row from an
I'm trying to add a pojo to a collection in another pojo. I'm sure
I am trying to insert a div inside another div using add() of jquery
I'm trying add a tab to my web page that looks like this: Using
trying to add an ExpiresDefault ExpiresByType to content on my website so that way
Trying to add a 'box' to a form at design time, I looked up
I am trying to animate a table row sliding up, then adding a new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.