JSFiddle - React, Tailwind, and code Playground
HTML
<section id="test_div">
</section>
<section id="second_div">
</section>
CSS
#test_div {
background: blue;
color: #FFF;
height: 100px;
margin: 0 0 50px;
width: 100%;
}
#test_div:hover {
background: red;
}
JavaScript
$(document).ready(function() {
function css(a) {
var sheets = document.styleSheets, o = {};
for (var i in sheets) {
var rules = sheets[i].rules || sheets[i].cssRules;
for (var r in rules) {
if (a.is(rules[r].selectorText)) {
o = $.extend(o, css2json(rules[r].style), css2json(a.attr('style')));
}
}
}
return o;
}
function css2json(css) {
var s = {};
if (!css) return s;
if (css instanceof CSSStyleDeclaration) {
for (var i in css) {
if ((css[i]).toLowerCase) {
s[(css[i]).toLowerCase()] = (css[css[i]]);
}
}
} else if (typeof css == "string") {
css = css.split("; ");
for (var i in css) {
var l = css[i].split(": ");
s[l[0].toLowerCase()] = (l[1]);
}
}
return s;
}
/*
$("#test_div").click(function() {
alert("clicked");
if (!$(this).hasClass("hovered")) {
alert("detected no hovered class");
$(this).addClass("hovered");
alert("added hovered class");
var hoverStyle = css($("#test_div"));
alert("created the hoverStyle variable");
$("#second_div").css(hoverStyle);
alert("applied the hoverStyle variable to #second_div");
}
});
*/
var hoverStyle = css($("#test_div"));
// alert("created the hoverStyle variable");
$("#second_div").css(hoverStyle);
// alert("applied the hoverStyle variable to #second_div");
});