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.

1

4 Answers 4

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

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

Comments

0

Try this...

$("table tr td.last").each(function () {
    $(this).parent().insertAfter($("table tr:last"));
});

Comments

0

try this:

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

DEMO

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.