0

For example, I have this code:

<table>
    <tr>
      <td class="last"></td>
      <td></td>
    </tr>
    <tr>
      <td class="last"></td>
      <td></td>
    </tr>
    <tr>
      <td class="another"></td>
      <td></td>
    </tr>
    <tr>
      <td class="another"></td>
      <td></td>
    </tr>
</table>

I want this to be set like this using javascript:

<table>
    <tr>
      <td class="another"></td>
      <td></td>
    </tr>
    <tr>
      <td class="another"></td>
      <td></td>
    </tr>
    <tr>
      <td class="last"></td>
      <td></td>
    </tr>
    <tr>
      <td class="last"></td>
      <td></td>
    </tr>
</table>

Just what is needed is, javascript should detect td with class "last" and take whole table row to bottom of the table.

LIGHT
  • 5,604
  • 10
  • 35
  • 78
  • possible duplicate of [How to rearrange elements using jQuery?](http://stackoverflow.com/questions/4909907/how-to-rearrange-elements-using-jquery) – Thilo Jun 20 '12 at 12:00

4 Answers4

1
var last = $( '.last' );
last.parent().parent().append( last.parent() );

JSFiddle Demo.

last.parent().parent() is the table element, and last.parent() is the tr element.

append moves the DOM elements, so they're not "copied", they're moved to the end.

Florian Margaine
  • 58,730
  • 15
  • 91
  • 116
1

You can use this plugin: http://tablesorter.com/docs/#Demo

Something more advanced: http://www.trirand.com/blog/jqgrid/jqgrid.html

0

Try this...

$("table tr td.last").each(function () {
    $(this).parent().insertAfter($("table tr:last"));
});
Dan Lister
  • 2,543
  • 1
  • 21
  • 36
0

try this:

$('td').each(function(){
  if ($(this).hasClass('another')) {
     $(this).insertBefore($('td:first'))
  }
})

DEMO

Ram
  • 143,282
  • 16
  • 168
  • 197