naeemqaswar
11/14/2016 - 10:29 AM

External to Inline CSS

External to Inline CSS

function makeStyleInline(){
    var rules = document.styleSheets[document.styleSheets.length-1].cssRules;
    for (var idx = 0, len = rules.length; idx < len; idx++) {
        $(rules[idx].selectorText).each(function (i, elem) {
            elem.style.cssText += rules[idx].style.cssText;
        });
    }
}
$.each(document.styleSheets, function(sheetIndex, sheet) {
    var style_data = '<style>';
    $.each(sheet.cssRules || sheet.rules, function(ruleIndex, rule) {
        style_data += rule.cssText;
    });
    style_data += '</style>';
    $('body').prepend(style_data);
    makeStyleInline();
});