css - jQuery convert applied classes to style attributes -


i working on bookmarklet project. when user clicks on bookmarklet can grab partial part of web page , view somewhere else.

the problem partial element (lets assume div) has css styles , classes applied.

is there way loop through child elements of selected div , convert class properties style properties can keep formatting?

for example below sample screenshot; need take out applied classes , convert them style attributes in selected area.

enter image description here

(function($) {     $.extend($.fn, {         makecssinline: function() {             this.each(function(idx, el) {                 var style = el.style;                 var properties = [];                 for(var property in style) {                      if($(this).css(property)) {                         properties.push(property + ':' + $(this).css(property));                     }                 }                 this.style.csstext = properties.join(';');                 $(this).children().makecssinline();             });         }     }); }(jquery)); 

you call using

$(".select").makecssinline(); 

the problem function brings every css property tag, can cause major performance hit, if willing take risk, go ahead

fiddle

function acquired here


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -