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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:13:35+00:00 2026-06-08T23:13:35+00:00

Say I have a table: <table id=myTable> <tbody> <tr> <td> <a class=removeLink >Remove</a> </td>

  • 0

Say I have a table:

<table id="myTable">
    <tbody>
        <tr>
            <td>
                <a class="removeLink" >Remove</a>
            </td>
        </tr>
        <tr>
            <td>
                <a class="removeLink" >Remove</a>
            </td>
        </tr>
    </tbody>
</table>
<a id="addLink">Add</a>

So the aim of the game here is that when a remove link is clicked the associated row will dissapear.

So I have some javascript:

<script type="text/javascript">
    $(document).ready(function () {

        $('.removeLink').click(function () {

            $(this).closest('tr').hide('slow');

        });

        $('#addLink').click(function () {

            $('#myTable').append('<tr><td><a class="removeLink" >Remove</a></td></tr>');

        });

    });
</script>

So I have the dissappearing part working with this.

However the add link adds a row to the table.

Now when I click the remove on a row that has been added it doesn’t dissapear. Makes sense as it hasn’t had its click
event set up.

How to code this so that links that are added will have their removeLinks hooked up to hide?

Also is this a strange way to even add the row? Is there a better way?

  • 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-08T23:13:37+00:00Added an answer on June 8, 2026 at 11:13 pm

    You can use on():

    $('#myTable').on('click', 'a.removeLink', function(e){
        $(this).closest('tr').remove();
    });
    

    on() essentially binds the named event(s) to the specified element (#myTable), and, on ‘hearing’ that, or those, event(s) inspects the target to see if it matches the supplied selector (the second of the parameters passed to the on() method. If it does, the anonymous, third parameter, function is executed.

    It seems better to bind the event-handling to the element closest to the elements affected by the event that exists in the DOM at the point of event-handling/binding. In this case that would be the tbody, which would result in the following (only-slightly) modified code:

    $('#myTable tbody').on('click', 'a.removeLink', function(e){
        $(this).closest('tr').remove();
    }
    

    Other alternatives are delegate() (though this has been superseded by on() from jQuery 1.7):

    $('#myTable').delegate('a.removeLink', 'click', function(e){
        $(this).closest('tr').remove();
    }
    

    Or live(), though this is deprecated as of jQuery 1.7, and, even where live() is available, delegate() is recommended in preference. That said:

    $('#myTable').live('click', 'a.removeLink', function(e){
        $(this).closest('tr').remove();
    }
    

    References:

    • delegate().
    • live().
    • on().
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a table: <table id=mytable> <tr class=old_row><td>1</td><td>2</td><td class=edit>Edit</td></tr> <tr class=old_row><td>1</td><td>2</td><td class=edit>Edit</td></tr> <tr
Say I have a table: <table id=#myTable> <tr> Section 1 <td> <table> <tr> Sub
I have a table say MyTable (myId,myStringCol1,myStringCol2,myStringCol3) When Using QUERY1 hibernateTemplate.find(SELECT new(myId,myStringCol1) from MyTable)
I have this problem where after a field (say Field3 in table MyTable) is
Say I have a table that goes clockwise like this: 2 1 3 0
Let's say I have a table that has a varchar field. If I do
Let's say I have this table: <table class=live_grid> <tr> <td> <h3>Something!</h3> </td> </tr> </table>
Say that I have a table and I run the following: Long key =
lets say I have create table mytable( a VARCHAR(200) b VARCHAR(200) c VARCHAR(200) )
Let's say I have a table with 15 columns called MyTable and an UPDATE

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.