Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save guillaumegarcia13/a334b29b294ec587f9d5f13118c70a66 to your computer and use it in GitHub Desktop.
Save guillaumegarcia13/a334b29b294ec587f9d5f13118c70a66 to your computer and use it in GitHub Desktop.
Turn CSS rules into inline style attributes using jQuery
(function ($) {
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;
});
}
$('style').remove();
$('script').remove();
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment