I have the following question.
I have a table, like the example below. The plan is to copy a row but not with a new class. The class should change in a remove class. Example in jsfiddle: http://jsfiddle.net/klaas3/wgRYR/ The goal is to keep the last row always green and the others red.
<table class="test">
<thead>
<tr>
<td>header 1</td>
<td>header 2</td>
<td>header 3</td>
<td>header 4</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>
I use the last column(with the new and remove class or red and green colors) as a button.
I have the following allready, but something seems to go wrong:
$("table.test tr.new:last td.new").click(function(){
$('table.test tr.new:last td.new').removeClass('new').addClass('remove').fadeIn("fast");
$('table.test tr.new:last').clone(true).insertAfter('table.test tr.new:last');
});
Mind you, I am not a very experienced jquery user. Also when the cell class is changed I will change the table row class as well with a db id. (But that I will try myself with a working sample).
EDIT:
You need to clone the element before changing the classes
Also to turn off/remove the click event handler use .off()
http://jsfiddle.net/XvDBC/