Scenario
I have created a page where the client can build their own page, calendars, widgets, articles etc. I have created a second Dynamic builder page where they can build their own newsletters.
Problem
All my css is referenced with classes, because mailers are very limited I have to add all styles inline.
Question
Is there a script I can run to grab all referenced styles via class, and add it to the relevant elements/tags inline-styles?
Example [simple]
<p class='txtBlack'>Hello World</p>
Converts to
<p class='txtBlack' style='color:#000;'>Hello World</p>
Hope this is clear enough to understand.
I’d use
element.currentStyleandwindow.getComputedStyle()for each element, then ‘manually’ read what I want and overwrite what I’m sure that doesn’t work in mail apps.I made example here: http://jsfiddle.net/Vmc7L/
Another way, is to read rules form style sheets and then apply them to inline style. But what if u got selectors like
.myClass:firstChild>.anotherClass? 😀 Maybe jquery can help.There’re methods you need: http://www.quirksmode.org/dom/w3c_css.html