Guest User

function invertTable(HTMLTable)

a guest
Nov 30th, 2012
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function invertTable(table) {
  2.     var $this = table;
  3.     var newrows = [];
  4.     $this.find("tr").each(function(){
  5.       var i = 0;
  6.       $(this).find("th").each(function(){
  7.         i++;
  8.         if(newrows[i] === undefined) { newrows[i] = $("<tr></tr>"); }
  9.         newrows[i].append($(this));
  10.       });
  11.       $(this).find("td").each(function(){
  12.         i++;
  13.         if(newrows[i] === undefined) { newrows[i] = $("<tr></tr>"); }
  14.         newrows[i].append($(this));
  15.       });
  16.     });
  17.     $this.find("tr").remove();
  18.     $.each(newrows, function(){
  19.       $this.append(this);
  20.     });
  21.  
  22.     $this.find("thead").html("<tr>"+$this.find("tr").html()+"</tr>");
  23.     $this.find("tbody tr").first().remove();
  24.   }
Advertisement
Add Comment
Please, Sign In to add comment