jQuery's .css
method returns computed style as well, and is better because it accounts for browser difference.
Specify style properties you want to get and store:
var color = $( "div.content" ).css( "background-color" );
var position = $( "div.content" ).css( "position" );
var overflow = $( "div.content" ).css( "overflow" );
Use them later:
$('div.contentUpdated').css('color', color).css('position', position).css('overflow', overflow);
jsFiddle Example
EDIT 1:
You could also loop through objects' style properties by writing a custom* jQuery plug-in:
$.fn.getStyleObject = function(){
var dom = this.get(0);
var style;
var returns = {};
if(window.getComputedStyle){
var camelize = function(a,b){
return b.toUpperCase();
}
style = window.getComputedStyle(dom, null);
for(var i = 0, l = style.length; i < l; i++){
var prop = style[i];
var camel = prop.replace(/\-([a-z])/, camelize);
var val = style.getPropertyValue(prop);
returns[camel] = val;
}
return returns;
}
if(dom.currentStyle){
style = dom.currentStyle;
for(var prop in style){
returns[prop] = style[prop];
}
return returns;
}
if(style = dom.style){
for(var prop in style){
if(typeof style[prop] != 'function'){
returns[prop] = style[prop];
}
}
return returns;
}
return returns;
}
jsFiddle Example
EDIT 2:
I have written for you a simple example of how to get one object's content and style, and later impose it on the new object. I simply used jQuery and its .each() iterator function:
$(function () {
var width = $("#div").css("width");
var height = $("#div").css("height");
var backgroundColor = $("#div").css("background-color");
var color = $("#div").css("color");
var font_weight = $("#div").css("font-weight");
var font_size = $("#div").css("font-size");
var content = $("#div").html();
// Append the original content
$("#updatedDiv").append(content);
//
// Store CSS properties in an array
var cssProperties = {
'width': width,
'height': height,
'background-color': backgroundColor,
'color': color,
'font-weight': font_weight,
'font-size': font_size
};
//
// Set CSS properties on the new object
$.each(cssProperties, function(key, value) {
$("#updatedDiv").css(key, value);
});
});
jsFiddle Example