How to create tables from column data instead of row data in HTML? -


according article @ w3 schools, 1 can create basic table in html this:

<table border="1">     <tr>         <td>row 1, cell 1</td>         <td>row 1, cell 2</td>     </tr>     <tr>         <td>row 2, cell 1</td>         <td>row 2, cell 2</td>     </tr> </table> 

from above, appears 1 enters data rows.

i have situation need enter of data columns. possible?

<table border="1">     <tc>         <td>row 1, cell 1</td>         <td>row 2, cell 1</td>     </tc>     <tc>         <td>row 1, cell 2</td>         <td>row 2, cell 2</td>     </tc> </table> 

you're best bet render table rows, , use javascript invert table

http://jsfiddle.net/csgk9/2/

the following code invert table (this sample code uses jquery)

     $("table").each(function() {         var $this = $(this);         var newrows = [];          $this.find("tr").each(function(){             var = 0;              $(this).find("td").each(function(){                 i++;                 if(newrows[i] === undefined) { newrows[i] = $(""); }                 newrows[i].append($(this));             });         });          $this.find("tr").remove();         $.each(newrows, function(){             $this.append(this);         });     }); 

update:

here version works th elements well: http://jsfiddle.net/zwdlj/


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -