JSFiddle - React, Tailwind, and code Playground

by Emre Erkan

HTML

<div id="test">This is some text</div>

<div id="test1"></div>

CSS

#test { color: #c00; }

JavaScript

$.fn.copyCSS = function(style, toNode) {
    var self = $(this),
        styleObj = {},
        has_toNode = typeof toNode != 'undefined' ? true : false;
    if (!$.isArray(style)) {
        style = style.split(' ');
    }
    $.each(style, function(i, name) {
        if (has_toNode) {
            toNode.css(name, getComputedStyle(self.get(0), name));
        } else {
            styleObj[name] = getComputedStyle(self.get(0), name);
        }
    });
    return (has_toNode ? self : styleObj);
}

var $m = $('div#test').width(300).height(200).copyCSS('width height color');
$("#test1").append($m.width, $m.height, $m.color);

function getComputedStyle(elm, style) {
    var computedStyle;
    if (typeof elm.currentStyle != "undefined") {
        computedStyle = elm.currentStyle;
    }
    else {
        computedStyle = document.defaultView.getComputedStyle(elm, null);
    }
    return computedStyle[style];
}