Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move <tr> with JQuery

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?

like image 711
Erdinç Özdemir Avatar asked Jul 09 '26 03:07

Erdinç Özdemir


1 Answers

Try this:

$('table tr td a').click(function () {
    $(this).closest('tr').after($('#change'));
});​

fiddle

like image 68
gpojd Avatar answered Jul 11 '26 21:07

gpojd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!