0

I have to do html table to excel file, i find a javascript code for it and its working great but my site has classes for elements. I want that classes attributes to style attribute with jquery function or something.

Example

css

.myTable
{
   background : black; color:white;
}

html

<table class="myTable"></table>

that is is i want ;

<table style="background : black; color:white;"></table>

when i do this, my excel file will be formated like in my site. there is any way to do this ?

alim
  • 677
  • 5
  • 19

4 Answers4

4

So you should rewrite all styles(inline, external, etc) associated with element to it's "style" attribute.

Under following link, there is a solution how to do that: Can jQuery get all CSS styles associated with an element?

Community
  • 1
  • 1
Tomasz Rozmus
  • 1,646
  • 13
  • 21
  • After three answers i think you only the person who read the question correctly. This is another answer on SO which is almost same to current one http://stackoverflow.com/questions/4307409/copying-css-to-inline-using-jquery-or-retaining-formatting-when-copying-stuff-f Thanks – rahularyansharma Apr 26 '13 at 11:33
2

I am posting this here just becuase OP wants it here . I have taken this solution from another so answer which can be find here .

  (function($) {
        $.extend($.fn, {
            makeCssInline: function() {
                this.each(function(idx, el) {
                    var style = el.style;
                    var properties = [];
                    for(var property in style) { 
                        if($(this).css(property)) {
                            properties.push(property + ':' + $(this).css(property));
                        }
                    }
                    this.style.cssText = properties.join(';');
                    $(this).children().makeCssInline();
                });
            }
        });
    }(jQuery));


    $('.myTable').makeCssInline();

MY JS FIDDLE LINK can also be find here

Community
  • 1
  • 1
rahularyansharma
  • 11,156
  • 18
  • 79
  • 135
0

use Jquery css method to apply

$('table').css({background:black,color:white}); //this will apply for all tables

or you can add that class also to the table via addClass()

$('table').addClass('myTable'); //this will apply for all tables

Ravi Gadag
  • 15,735
  • 5
  • 57
  • 83
0

Here is the css selector to style all tables:

table
{
   background : black; color:white;
}
basarat
  • 261,912
  • 58
  • 460
  • 511