Reputation: 451
I have this table :
<table border="0" class="tab_cadrehov">
<tbody>
<tr class="tab_bg_1">
<td valign="top"><a id="User_245_245" href="/dailyTickets/front/contacts.form.php?id=245">Gov0N</a></td>
<td valign="top">ContactName</td>
<td valign="top"><a href="mailto:[email protected]">[email protected]</a></td>
</tr>
<tr class="tab_bg_2">
<td valign="top"><a id="User_695_695" href="/dailyTickets/front/contacts.form.php?id=695">iLgOP</a></td>
<td valign="top">ihi</td>
<td valign="top"><a href="mailto:[email protected]">[email protected]</a></td>
</tr>
</tbody>
</table>
what i want is to delete the a element in each first td in the (tr
,table
) , and then give the deleted a element to the second td
element in the (tr
,table
) , to be like this :
<tr class="tab_bg_1">
<td valign="top">Gov0N</td> // delete the a element from here , but keep the inside text
<td valign="top"><a id="User_245_245" href="/dailyTickets/front/contacts.form.php?id=245">ContactName</a></td> // add it here , around the text
.........
</tr>
<tr class="tab_bg_2">
<td valign="top">iLgOP</td>
<td valign="top"><a id="User_695_695" href="/dailyTickets/front/contacts.form.php?id=695">ihi</a></td>
.....
</tr>
Upvotes: 0
Views: 119
Reputation: 11264
$('tr').each(function() {
var link = $(this).find('td:first a');
text_of_second_td = $(this).find('td:nth-child(2)').text();
$(this).find('td:first').html(link.text()); //Link's text to the first td
link.text(text_of_second_td); //Replace Link's text by the second td's text
$(this).find('td:nth-child(2)').html(link); //Link to the second td
});
Upvotes: 2