What I am trying to do is take the last colomn in a table placed into a new table altogether. I got this working the problem is I want this to work for multiple tables with the same class names. Right now it only takes the first tables cols and repeats them. I have an idea of why but I am not sure how to target each table as an individual element even though they all have the same class name.
jquery
function fixLastColumn() {
// makes new table
var nt = $('<table class="ft_fixedTable"></table>');
$(".ft_FixedTable tr").each(function(i) {
nt.append('<tr class="ft_fixTR"><td class="ft_fixTD">'+$(this).children('td:last').html()+'</td></tr>')
})
nt.appendTo('.fixedDiv');
// remove last column
$('.ft_FixedTable tr').each(function(i) {
$(this).children('td:last').remove();
});
}
$(document).ready(function() {
fixLastColumn();
});
html
<table class="ft_FixedTable">
<thead>
<tr>
<td>Title 1</td>
<td class="ft_fixedCol">fixed one</td></tr>
</thead>
<tr>
<td>Content Content Content Content Content</td>
<td>Fixed content </td>
</tr>
</table>
<div class="fixedDiv"></div>
You can use JavaScript to move the table cells themselves instead of just copying the contents:
As a (small but potentially significant) optimization, however, you should use IDs instead of classes to identify your tables and divs:
http://jsfiddle.net/mblase75/TVpHp/