For example, if I have CSS that is included in the document:
div { color: red; } div.test { border: 1px solid blue; }
and the html tag inside the document body:
<div id='demo'> <div class='test'>123</div> <div>456</div> </div>
I want to convert everything to #demo as a string containing a tag with all the styles that it used, for example:
var parent = $('#demo'); var result = convertExternalInternalStylesToInline(parent);
I need the contents of the function convertExternalInternalStylesToInline , which automatically extracts all descendant elements, applies the computed / used styles, then adds CSS styles for these elements, and then returns it all as an html string.
Is it possible to use only client side javascript ? If so, how?
(I need to know how to get all calculated / used styles for the tag)
minimal example:
function convertExternalInternalStylesToInline(parent) { var parent = $(parent).clone(); // clone it before modify, is this deep clone? parent.find('*').each(function(idx,el){ // fetch all children var el = $(el); // convert to jquery object // get all applied styles on this element // el.? // --> don't know how // apply css for each styles el.css( css_prop, css_style ); }); // return as string, maybe: return parent.html(); }
javascript html css
Kokizzu Jan 15 '15 at 6:09 2015-01-15 06:09
source share