I do have a table, to manipulate, but i giving a sample here.. is my table contains the th and td, i suppose to find a column using the th’s title, and i need to move that column in to where i want.
in my case i made a work, and trying to append to morning column after the evening, but i am getting wrong result any one correct me?
HTML:
<table>
<tbody>
<tr>
<th>Morning</th>
<th>Afternoon</th>
<th>Evening</th>
</tr>
<tbody>
<tbody>
<tr>
<td>go to School</td>
<td>go to Lunch</td>
<td>go to Sleep</td>
</tr>
</tbody>
</table>
jQuery code:
var morningIndex = $('tr th:contains(Morning)').index();
var Evening = $('tr th:contains(Evening)');
$.each($('tr'), function(n,v){
morningCol = $(v).children().get(morningIndex);
$(Evening).after(morningCol);
})
this is working for me:
Thanks all.