Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8208445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:22:18+00:00 2026-06-07T09:22:18+00:00

I am converting table structured data into div using below code. $(‘#content’).html($(‘#content’).html() .replace(/<tbody/gi, <div

  • 0

I am converting table structured data into div using below code.

$('#content').html($('#content').html()
             .replace(/<tbody/gi, "<div id='table'")
             .replace(/<tr/gi, "<div style='overflow:auto;padding-top:15px;'")
             .replace(/<\/tr>/gi, "</div>")
             .replace(/<td/gi, "<span  style='float:left;margin-right:20px;'")
             .replace(/<\/td>/gi, "</span>")
             .replace(/<\/tbody/gi, "<\/div")); 

It works good mostly in all scenario except ROWSPAN & COLSPAN case.

How can I handle that design issue while converting Table into Div ?
I am stuck in that.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T09:22:20+00:00Added an answer on June 7, 2026 at 9:22 am

    Maybe this gets you in the right direction:

    .replace(/rowspan="/gi, 'class="rowspan-')
    .replace(/colspan="/gi, 'class="colspan-')
    

    Then make styles for the classes (e.g. rowspan-2 or colspan-3 etc.). However, this doesn’t solve cases where one element has both row- and colspan, but it’s a start.

    A better way would be:

    var copyAttr = function(old, $new) {
      for(var i = 0,
            attributes = old.attributes;
        i < attributes.length; i++) {
    
        $new.attr(attributes[i].name, attributes[i].value);
      }
      return $new;
    }
    
    $('#content').find('tbody').each(function() {
      var $new = copyAttr(this, $('<div id="table"></div>');
      $(this).replaceWith($new);
    }).end().find('tr').each(function() {
      var $new = copyAttr(this, $('<div class="tr"></div>');
      $(this).replaceWith($new);
    }).end().find('td').each(function() {
      var $new = copyAttr(this, $('<span class="td"></span>');
      $(this).replaceWith($new);
    });
    

    So now you have replaced the whole table structure with divs and spans with all the attributes the table elements had. Next you can change the row- and colspan attributes to classes.

    $('#table .td').each(function() {
      var $t = $(this);
      $t
        .addClass('rowspan-'+$t.attr('rowspan'))
        .removeAttr('rowspan')
        .addClass('colspan-'+$t.attr('colspan'))
        .removeAttr('colspan');
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am converting MySQL table into HTML table using this PHP snippet, and it
I am parsing data from a json file and converting to a HTML table,
I am converting a CSV file into a table format, and I wrote an
I'm using PetaPoco T4 Template (http://www.hanselman.com/blog/T4TextTemplateTransformationToolkitCodeGenerationBestKeptVisualStudioSecret.aspx), It always converting table names, for example it
I am converting an old dataset into a newly structured database. Currently they have
I'm converting data from one schema to another. Each table in the source schema
For some reason, my mysql table is converting single and double quotes into strange
Converting an old program into an ASP.NET c# site. I have a table full
I have a problem when converting a static html table to one which is
What is the php script for converting a mysql table to text file? I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.