Jump to content

How to reverse order of <td>'s in a <table> using jQuery?


Recommended Posts

Good morning!

 

I've googled the question, but could not find the information. There is a <table> with random number of <td>s (each <tr> contains 3 <td>s). How to reverse the order of each <td> in this table? The initial order is: 

<table><tr><td1></td><td2></td><td3></td></tr> 
       <tr><td4></td><td5></td><td6></td></tr></table>

I need:

<table><tr><td6></td><td5></td><td4></td></tr> 
       <tr><td3></td><td2></td><td1></td></tr></table>

Would appreciate any assistance or idea!

You could use getElementsByTagName() to get the table and then all the columns for the table. More information can be found here:

https://developer.mozilla.org/en-US/docs/Web/API/Element/getElementsByTagName

 

Then you could loop through the columns, rebuild the table, and replace the old table with the new one.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.