Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert multiple columns html table to a single column for Mobile friendly layout

I have a table with 3 columns. I would like to convert to single row.

enter image description here

both append.('</tr><tr>') and after.('</tr><tr>') do not work.

Want it like this for mobile friendly page -

enter image description here

Thank you for your help!

http://jsfiddle.net/tZt3Q/

like image 781
Win Avatar asked Dec 01 '22 21:12

Win


1 Answers

One way you can achieve this is by using JQuery wrap method. See Wrap and UnWrap

Demo

Demo W/O class

 $(document).ready(function () {
    var tbl = $("table");
      $('td','table').unwrap().each(
     function () {     
          tbl.append($(this).wrap('<tr>').parent()); 
    });
  });

Much simpler one:

 $(document).ready(function () {
    $('table').find('td').unwrap().wrap($('<tr/>'));
});

Fiddle

like image 84
12 revs Avatar answered Dec 04 '22 11:12

12 revs