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 9229089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:29:11+00:00 2026-06-18T05:29:11+00:00

So I have a table, and every time the button gets submitted it adds

  • 0

So I have a table, and every time the button gets submitted it adds a row to the table with 4 columns, I place a delete button in each row. My purpose is to be able to delete the entire row, but when I press it it only deletes the button. How can I delete the entire row?

$(this).parent().remove()

I tried this but it doesn’t work, the td is directly within the tr so it should access the tr and delete it but the row still exists.

  • 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-06-18T05:29:13+00:00Added an answer on June 18, 2026 at 5:29 am

    You want to select the closest tr element, not the immediate parent. Without seeing your event binding, I’d guess that $(this) is the button, and that $(this).parent() is the <td>. Instead you should try:

    $(this).closest('tr').remove();
    

    Or, if you can guarantee a specific hierarchy of tr>td>button, then you could use:

    $(this).parent().parent().remove();
    

    I strongly discourage using the latter format, as it is tightly coupled to the structure of the HTML. If your HTML starts out as:

    <tr>
        <td>
            <button>Example</button>
        </td>
    </tr>
    

    and later changes to:

    <tr>
        <td>
            <div class="wrapper">
                <button>Example</button>
            </div>
        </td>
    </tr>
    

    using closest('tr') will continue to work, but using parent().parent() will break.


    Relating to your secondary issue of not having events fired. If you’re binding events with $('.foo button').click(removeRow); (where .foo matches the table element), the events won’t apply to newly created button elements. Instead you should be using the event-delegation form of on (or simply delegate if you’re using an older version of jQuery):

    $('.foo').on('click', 'button', removeRow);
    

    This would store the event binding on the table element, and when the callback gets called, it would check to see if the element that triggered the specified event matches the selector specified in the second argument (in this case 'button') if it matches, it triggers the specified handler (in this case removeRow) in with the matched element as the context (within the handler, this would still point to a button element).

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

Sidebar

Related Questions

I have a MYSQL-Table which stores scores. Every time a user improves a new
I have a table where every row has a unique id. The last table
I have sectioned table view with check selection for each section(every section allows only
I have a nice modal showing a delete confirmation dialog each time user wants
I have two tables, news and news_views. Every time an article is viewed, the
I have a table that someone update this table every day. I would like
i have 5 tables,in every table it has 4 rows. so i need to
We have a database where every table name starts with WW. I want to
I have a table view with a custom cell ( UISwitch on every cell
I have a table on which I want to perform some operations every hour.

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.