www.webdeveloper.com
Results 1 to 2 of 2

Thread: Re-Ordering table columns

Hybrid View

  1. #1
    Join Date
    Aug 2013
    Posts
    1

    Re-Ordering table columns

    I hope there is help out there.

    I have a 3 column table. It displays results from a pool match. But the software I use to generate the html page currently shows

    Player A - Player B - Result

    What I hope to achieve is

    Player A - Result - Player B

    Here is the table I working with, on a small scale.

    <TABLE class="table1">
    <TR>
    <TD class="ko3-text">Geraldo Depp(Dun Mare)</TD>
    <TD class="ko3-text">Darin Hanley(Bradford B)</TD>
    <TD class="ko-data">7- 5</TD>
    </TR>
    </TABLE>

    Can anybody help me swap Column 2 and 3?

  2. #2
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,648
    try this

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Swap Cells</title>
    <script type="text/javascript">
    function swapper(tab){
    var trs=tab.rows;
    for(var i=0;i<trs.length;i++){
    var c1=trs[i].cells[1],val1=c1.innerHTML,c2=trs[i].cells[2],val2=c2.innerHTML;
    c1.innerHTML=val2;c2.innerHTML=val1;
    }
    }
    window.onload=function(){document.getElementById('swp').onclick=function(){swapper(document.getElementsByTagName('table')[0]);}}
    </script>
    </head>
    <body>
    <center>
    <table class="table1">
    <tr>
    <td class="ko3-text">Geraldo Depp(Dun Mare)</td>
    <td class="ko3-text">Darin Hanley(Bradford B)</td>
    <td class="ko-data">7- 5</td>
    </tr>
    <tr>
    <td class="ko3-text">Player A</td>
    <td class="ko3-text">Player B</td>
    <td class="ko-data">Score A - B</td>
    </tr>
    <tr>
    <td class="ko3-text">Player C</td>
    <td class="ko3-text">Player D</td>
    <td class="ko-data">Score C - D</td>
    </tr>
    </table>
    <br /><br /><br />
    <a href="#null" id="swp">swap</a>
    </center>
    </body>
    </html>
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles