function getElementStyle(selector) { var element = document.querySelector(selector); return element.currentStyle ? element.currentStyle : window.getComputedStyle(element, null); } function getElementStyleValue(selector, cssAttr, isRem) { var fontSize = parseFloat(getElementStyle(‘html‘).fontSize), elementStyle = getElementStyle(selector); value = parseFloat(elementStyle[cssAttr]), isRem != false?isRem = true:‘‘; if(isRem) { value = (value/fontSize).toFixed(4) + "rem"; } else { value = value.toFixed(4)+"px"; } console.log(value); return value; } var value1 = getElementStyleValue(‘.sp2‘, ‘width‘); var value2 = getElementStyleValue(‘.sp2‘, ‘width‘, false); alert(value1+value2);