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

  • Home
  • SEARCH
  • 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 7520721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:07:05+00:00 2026-05-30T02:07:05+00:00

I need a way to add or remove a row below another row in

  • 0

I need a way to add or remove a row below another row in my html table. I’m using the dom, and can add and remove rows easily enough, but the problem comes up when I try to have a button column that adds and removes rows dynamically.

For example:

    |  Item Type  |     Item     |  Add/Remove Item
====================================================
    |   Fruit >   |     Apple    |   [ Add new ]
----------------------------------------------------
    |             |     Mango    |   [ Remove ]
----------------------------------------------------
    |             |     Pear     |   [ Remove ]
----------------------------------------------------

The [Add new] and [Remove] entries in the right column are buttons. Clicking a [Remove] button would delete the row (remove the pear or mango row). Clicking the [Add new] button would add a new Item (a new fruit).

If I specified the html for the button and added a new row based on an onClick, I can’t think of a way to keep track of which row the button clicked from to add the new one. The best way I can think of is to have an array that keeps track of all the item types and what row they are on, then pass the id or name of the item into the method from onClick(), but this seems error-prone and messy.

To solve this, I’m willing to consider any solution (jquery plugin, javascript code, anything). Can someone point me to the best way to accomplish this?

  • 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-30T02:07:05+00:00Added an answer on May 30, 2026 at 2:07 am

    Like this? I do not know where you are going to take values ‘Mango’ and ‘Pear’..
    http://jsfiddle.net/vPatQ/

    $('.AddNew').click(function(){
       var row = $(this).closest('tr').clone();
       row.find('input').val('');
       $(this).closest('tr').after(row);
       $('input[type="button"]', row).removeClass('AddNew')
                                     .addClass('RemoveRow').val('Remove item');
    });
    
    $('table').on('click', '.RemoveRow', function(){
      $(this).closest('tr').remove();
    });
    

    for html code

    <table>
        <tr><td>Item Type</td><td>Item</td><td>Add/Remove Item</td></tr>
        <tr><td><input type='text' value='Fruit >'></td>
            <td><input type='text' value='Apple'></td>
            <td><input type='button' class='AddNew' value='Add new item'></td></tr>
    </table>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to programmatically add and remove rows from a Word 2010 table. Unfortunately
I need some way to add a class attribute to the output of the
I need a way to easily export and then import data in a MySQL
I need a way to determine the type of an HTML element in JavaScript.
I need to keep track of indexes/rows that are selected. When a row is
For a customer project, I need to be able to add/remove tags from items
I need to be able to add and remove an arbitrary number of points
I need to add/remove SAMBA shares through PHP or via SSH (ssh link from
I need to monitor a folder and its subdirectories for any file manipulations (add/remove/rename).
Need a way to allow sorting except for last item with in a list.

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.