0

After a click on a 'td' of table 1, i append some cells from that row to another table (table 2) without moving/changing that row from table 1.

Now to avoid duplication i added class to that 'td' from table 1. Like this

$(".table1 td:first-child + td").click(function(){

  $("#table2").append('<tr><td>clicked TD value from table 1</td>  more td's</tr>');  
  $(this).addClass('done'); 
}):

Now when i tried to remove that appended row from table2...i have to remove the class 'done' which is i added to cliked 'td' of table1.

How to do this?? is there any other way of doing this (avoiding duplication) other than adding class??

Here's the fiddle.

pls help. thanks

HungryDB
  • 555
  • 3
  • 11
  • 30
  • Can you please bring more info ? A [fiddle](http://jsfiddle.net/) might be useful to see what you are exactly trying to do and get all constraints involved `;)` – Stphane Oct 16 '13 at 09:26
  • instead you have to pass something unique to both row like done1, so while remove table2 row you can get it correspond row of table1 – rajesh kakawat Oct 16 '13 at 09:30
  • @f00bar, just added fiddle in the post. – HungryDB Oct 16 '13 at 10:57
  • When i click on the 'name' field ..nothing gets appended thats the first problem.. and when removing that row from 2nd table how to remove the class which i added??? – HungryDB Oct 16 '13 at 11:00
  • So basically you want to duplicate rows from table selection into #destiny table when clicking any name from table selection, but not if the name you clicked has it's row already copied into the #destiny table right ? – Stphane Oct 16 '13 at 12:05
  • yeah, exactly.. f00bar – HungryDB Oct 16 '13 at 12:27

1 Answers1

1

Here is a deep revision of your code

Fiddle HERE

$(function () {
    $("#selections tbody").on('click', function (e) {
        var $td = $(e.target);
        if ($td.prevAll('td').length === 1) {
                var $destiny = $('#destiny'),
                                // Any row in destiny that would be a clone of the current clicked td's row
            // You may want to put an id to make sure it is uniq
                $trDestiny = $('tr[rel="' + $td.text() + '"]', $destiny);
                // ...
            if (!$trDestiny.length) {
                // Insert new row ...
            }
            // else {error handling here}
        }
    });
});
Stphane
  • 3,368
  • 5
  • 32
  • 47
  • http://jsfiddle.net/KPe9T/6/ i updated the fiddle, i couldn't understand some of the code ...will you elaborate .??? – HungryDB Oct 16 '13 at 15:40
  • Sure, I can ! Now check [8th revision](http://jsfiddle.net/KPe9T/8/)... By the way, please set the answer as the solution to consider my work `;)` – Stphane Oct 17 '13 at 12:38