I\'ve been working on styling different parts of my website for a while, however I have yet to put my inline styles into a stylesheet. I was wondering if a tool exists to parse
Here, I wrote a function to do it (the specificity won't be perfect, but it'll get you started):
function getInlineStyles() {
var stylesList = "",
thisElement,
style,
className,
id;
$("*", "body").each(function () {
thisElement = $(this);
style = thisElement.attr("style");
className = thisElement.attr("class");
id = thisElement.attr("id");
if (id !== undefined) {
stylesList += " #" + id;
}
if (className !== undefined) {
stylesList += " ." + className;
}
if (id !== undefined || className !== undefined) {
stylesList += "{";
}
if (style !== undefined) {
stylesList += style;
}
if (id !== undefined || className !== undefined) {
stylesList += "}";
}
});
return stylesList;
}