0

I have problem reversing table columns. I've tried a few things but they didn't work at all. My knowledge of jQuery/javascript is poor but I need it for school purposes. The function should be made in JavaScript or jQuery

<table>
  <tr id="header">   
    <th><a href="#">Rbr</a></th>   
    <th><a href="#">Ime</th>   
    <th><a href="#">Prezime</th>  
  </tr>
  <tr id="tabela">   
    <td>1.</td>   
    <td>Pera</td>   
    <td>Mikic</td>  
  </tr>
  <tr id="tabela">   
    <td>2.</td>   
    <td>Mika</td>   
    <td>Zikic</td>  
  </tr>
  <tr id="tabela">   
    <td>3.</td>
    <td>Zika</td>
    <td>Peric</td>  
  </tr>
</table>

I want to reverse 1,2,3 to 3,2,1 by clicking on header Rbr. Pera,Mika,Zika to Zika,Mika,Pera by clicking on header Ime. Mikic,Zikic,Peric to Peric,Zikic,Mikic by clicking on header Prezime

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Custi
  • 1
  • 1
  • 2
    Your question is too broad as it stands as you've shown no attempt to solve this yourself in the question. As a hint, what you need to search for is the `sort()` method in JS. – Rory McCrossan Nov 27 '16 at 21:49
  • I did try sort() and reverse() but i have no idea how to connect it to specific collumn – Custi Nov 27 '16 at 21:51
  • In jQuery you can use `eq()` to get an element by its index: http://api.jquery.com/eq – Rory McCrossan Nov 27 '16 at 21:51
  • Gonna try it out now @RoryMcCrossan – Custi Nov 27 '16 at 21:53
  • the duplicate I marked also has a solution for this exact problem. I would strongly suggest that if you're learning you use that code for a reference and inspect every line to understand exactly what it does and why. – Rory McCrossan Nov 27 '16 at 21:54

0 Answers0