I am dealing with an HTML page that looks like this:
<div id="cloneDiv">
<h1>
<a href="">ASUS Vivotab Smart Black Office 2013 H&S ME400C-C2-BK 10.1-Inch 64GB Tablet
(Black)</a>
</h1>
<div id="fordBackgroundImage" style="display: inline-block; background-position: center center; width: 1200px;
height: 565px; background-image: url('http://www.ford.com/ngbs-services/resources/ford/edge/2013/npcolorizer/edg13_ingotsilver.jpg');
background-repeat: no-repeat; background-attachment: scroll; position: relative;">
<div style="position: absolute; color: white; font-weight: bold; top: 50px; left: 100px; font-size: 50px;">
Try new ford jeep!
</div>
</div>
<p>
<img alt="" src="http://ecx.images-amazon.com/images/I/81UsKLK%2B6LL._SX342_.jpg"
class="border thumb0 selected" style="cursor: pointer;">
</p>
<p>
<img border="0" src="http://g-ecx.images-amazon.com/images/G/01/kindle/otter/dp/o1_slate_sm._V358729399_.jpg"
style="width: 320px; height: 282px;">
</p>
</div>
I have a JavaScript function that converts elements to computed style elements:
function MakeCssInline(elementParam) {
var domE = $(elementParam).get()[0];
var cssText = window.getComputedStyle(domE).cssText;
$(elementParam).attr("style", cssText);
// children
var items = domE.getElementsByTagName("*");
for (var i = 0; i < items.length; i++) {
var domE2 = items[i];
var cssText2 = window.getComputedStyle(domE2).cssText;
$(items[i]).attr("style", cssText2);
}
};
When I call this function on the original element, it works fine but changes the original element's HTML:
MakeCssInline($("#cloneDiv"));
However, when I try to call this function on a cloned element, it does not work:
var cloneElement = $("#cloneDiv").clone();
MakeCssInline(cloneElement);
The styles are not applied to the element because I did not append it to the body element. Since I don't want to interfere with the original element, is there a way to get the computed style of a cloned element using JavaScript?