I have a table on my page like this:
<table border="1">
<tr>
<td>first</td>
<td><a href="#">first click</a></td>
</tr>
<tr>
<td>second</td>
<td><a href="#">second click</a></td>
</tr>
<tr>
<td>third</td>
<td><a href="#">third click</a></td>
</tr>
<tr id="change">
<td colspan="2">
<button>change</button>
</td>
</tr>
</table>
When I click on of the links, I want the move '#change' under the clicked link's . For example; when I click on "first click" table changes like this..
<table border="1">
<tr>
<td>first</td>
<td><a href="#">first click</a></td>
</tr>
<tr id="change">
<td colspan="2">
<button>change</button>
</td>
</tr>
<tr>
<td>second</td>
<td><a href="#">second click</a></td>
</tr>
<tr>
<td>third</td>
<td><a href="#">third click</a></td>
</tr>
</table>
How can I do it with JQuery?
Try this:
$('table tr td a').click(function () {
$(this).closest('tr').after($('#change'));
});
fiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With