JSFiddle - React, Tailwind, and code Playground
HTML
<div id="e1"></div>
<div id="e2"></div>
CSS
#e1{
width: 65%;
}
#e2{
width: 65px;
}
JavaScript
jQuery( document ).ready( function(){
var e1 = jQuery( "#e1"), e2 = jQuery("#e2");
e1.html( getStyle( e1[0], "width" ) );
e2.html( getStyle( e2[0], "width" ) );
});
(function(){
var docElm = document.documentElement;
matchesSelector = docElm.matchesSelector ||
docElm.mozMatchesSelector ||
docElm.webkitMatchesSelector ||
docElm.msMatchesSelector ||
docElm.oMatchesSelector;
if( !matchesSelector ) {
throw new Error( "no browser support");
}
function getStyle( element, style ) {
var styleSheets = document.styleSheets,
styleSheet, rule, rules, i,j,k,l,
candidate, candidates = [], latestVal;
l = styleSheets.length;
for( i = 0; i < l; ++i ) {
styleSheet = styleSheets[i];
rules = styleSheet.cssRules || styleSheet.rules;
if( !rules ) {
continue;
}
k = rules.length;
for( j = 0; j < k; ++j ) {
rule = rules[j];
if( matchesSelector.call( element, rule.selectorText ) ) {
candidates.push( rule );
}
}
}
l = candidates.length;
if( !l ) {
return element.style[style];
}
for( i = 0; i < l; ++i ) {
candidate = candidates[i];
if( style in candidate.style ) {
latestVal = candidate.style[style];
}
}
return latestVal || element.style[style];
}
window.getStyle = getStyle;
})();