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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:43:51+00:00 2026-06-15T03:43:51+00:00

Yesterday i questioned how to add a new table row but change the css

  • 0

Yesterday i questioned how to add a new table row but change the css of the duplicated row. I got an answer to that question!(link) however a new issue has arised.

i have a table as follow:

<table class="test">
<thead>
<tr>
    <td><b>header 1</b></td>
    <td><b>header 2</b></td>
    <td><b>header 3</b></td>
    <td><b>header 4</b></td>
</tr>
</thead>
<tbody>
<tr class="1">
    <td>data 1</td>
    <td>data 2</td>
    <td>data 3</td>
    <td class="remove"></td>
</tr>
<tr class="2">
    <td>data 1</td>
    <td>data 2</td>
    <td>data 3</td>
    <td class="remove"></td>
</tr>
<tr class="new">
    <td>data 1</td>
    <td>data 2</td>
    <td>data 3</td>
    <td class="new"></td>
</tr>
</tbody>
<table>​

Jquery code:

$("table.test tr.new:last td.new").click(function(){
     var x = $('table.test tr.new:last').clone(true);
     $(this).removeClass('new').addClass('remove').off('click');    
     x.insertAfter('table.test tr.new:last');
});
     $("table.test tr td.remove").click(function(){
     $(this).closest("tr").fadeOut('slow');
});

When i click the td.new cell i want to add a row. This is working. Also the class is changed in a td.remove cell. However the click events do not work correct. The remove cell should allways remove a row. I have figured out that I have to use .off() and .on functions but I can’t seem to understand the logic behind this functions. The following image is what i am aiming for: postimage

Jsfiddle example of what i have now can be found here

  • 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-15T03:43:54+00:00Added an answer on June 15, 2026 at 3:43 am

    You seem to adding the row Dynamically right.. So you need to delegate the event..

    Instead of

    $("table.test tr td.remove").click(function(){
    

    try

    $("table.test").on('click','td.remove', function(){
    

    Check Fiddle

    UPDATE

    You can handle both the case in a single handler itself..
    Made a few modifications in your code..

    $("table.test").on('click', 'td.remove,td.new', function() {
        var $this = $(this);
        if ($this.hasClass('new')) {
            var x = $('table.test tr.new').clone();
            $this.removeClass('new').addClass('remove');
            $this.closest('tr').removeClass('new');
            x.insertAfter('table.test tr:last');
        }
        else if ($this.hasClass('remove')) {
            $(this).closest("tr").fadeOut('slow');
        }
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I asked a question yesterday which got answers but didnt answer the main point.
I asked this question yesterday got a pretty good answer but can't figure out
I asked a similar question yesterday, but recognize that i need to rephase it
This question is in relation to a question I posted yesterday. The link -http://stackoverflow.com/questions/12636348/how-to-add-a-different-class-to-the-same-class-in-jquery
I asked a similar question yesterday that was specific to a technology, but now
yesterday i asked one question and got the answer from our friend here, and
I asked a question yesterday on here and got some awsome help, but I
I asked a question yesterday and the answer I got has answered the first
I posted this question yesterday but received some valuable feedback that my post left
i asked this question yesterday but it doesnt seem to have asked properly so

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.