The jQuery .css
method returns the calculated style as well, and better because it takes into account the difference in the browser.
Specify the style properties that you want to retrieve and save:
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:
, * jQuery:
$.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
2:
, , . jQuery . Each() :
$(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();
$("#updatedDiv").append(content);
var cssProperties = {
'width': width,
'height': height,
'background-color': backgroundColor,
'color': color,
'font-weight': font_weight,
'font-size': font_size
};
$.each(cssProperties, function(key, value) {
$("#updatedDiv").css(key, value);
});
});
jsFiddle