in my program, I try to copy an element, using .clone() method, but this method doesnt copy the element's styles, so I have to translate them one by one like this :
var style = {
"position":"absolute",
"color": $(demo[i][1]).css("color"),
"width": $(demo[i][1]).width(),
"height": $(demo[i][1]).height(),
"font-size": $(demo[i][1]).css("font-size"),
"font": $(demo[i][1]).css("font"),
"text-align": $(demo[i][1]).css("text-align"),
"padding-left": $(demo[i][1]).css("padding-left"),
"padding-right": $(demo[i][1]).css("padding-right"),
"padding-top": $(demo[i][1]).css("padding-top"),
"padding-bottom": $(demo[i][1]).css("padding-bottom"),
}
and then use .css method to apply these styles, but it seems like a stupid idea to copy these one by one. so is there any better way to copy an element so its styles are also copied, than .clone() method, and if not, is there any way to automatically mapp all possible css() results without going to all of these troubles ?
here's my new approach, any better way ?
var styleList = ['background', 'border', 'outline','font', 'list-style', 'padding', 'display', 'float','overflow', 'visibility', 'width', 'height', 'border-collapse', 'border-spacing', 'caption-side', 'empty-cells', 'table-layout', 'color', 'direction','letter-spacing', 'line-height', 'text-align', 'text-decoration', 'text-indent', 'text-transform', 'vertical-align', 'white-space', 'word-spacing']
var style = {'position':'absolute'}
$.each( styleList, function(i, property){ style[property]= original.css(property) });