0

Is it possible to flip/reverse td values of a table.

If I fx: put a class on the td section I want flipped and name it 'valuesToFlip'

$('.valuesToFlip').reverse() // not working.
2
  • 1
    What do you mean by reverse? Change text from this to siht? Or reverse the order of the td cells in the row? Or reverse the order of td in the entire table...? Commented Mar 30, 2016 at 13:02
  • reverse the ordering of the elements. Commented Mar 30, 2016 at 13:08

1 Answer 1

2

reverse() can be used with array, to convert it to array use get() and apply reverse(). Now for updating the order append back them using append()

var $td = $('.valuesToFlip');
$td.parent().append($td.get().reverse());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table>
  <tr>
    <td class="valuesToFlip">1
    </td>
    <td class="valuesToFlip">2
    </td>
    <td class="valuesToFlip">3
    </td>
  </tr>
</table>

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

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.