I tried to change this plugin for your needs:
(function($){ $.fn.copyStyle = function(jqCopyTo,styleStartsWith,overideStyle){ 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]; for(var m = 0; m < styleStartsWith.length; m++){ if(prop.lastIndexOf(styleStartsWith[m], 0) === 0) { var camel = prop.replace(/\-([az])/g, camelize); var val = style.getPropertyValue(prop); returns[camel] = val; overideStyle==true ? $(this).css(prop,0):null; } } }; }; if(style = dom.currentStyle){ for(var prop in style){ for(var m = 0; m < styleStartsWith.length; m++){ if(prop.lastIndexOf(styleStartsWith[m], 0) === 0) { returns[prop] = style[prop]; overideStyle==true ? $(this).css(prop,0):null; } } }; };
in such a structure:
#inner { margin:20px; padding:20px; background-color:#F00; } #wrapper { background-color:#f80; }
HTML:
<div id="wrapper"> <div id="inner"> Table Content </div> </div>
you can use this plugin as follows:
$("#inner").copyStyle("#wrapper",["margin","padding"],true);
the result is that the edge of the inner margin and the indentation will be overwritten and the style added to the wrapper-div. you can handle the override behavior with the last boolean indicator.
here is a complete example on jsFiddle . I can not guarantee that it works in all browsers (just tested Firefox and ie9)
source share