Skip to content

Instantly share code, notes, and snippets.

@bchumney
Created December 2, 2014 18:11
Show Gist options
  • Save bchumney/4155600bc4e7dcde1d49 to your computer and use it in GitHub Desktop.
Save bchumney/4155600bc4e7dcde1d49 to your computer and use it in GitHub Desktop.
Element Style Values with Plain JS
function getStyle(oElm, strCssRule){
var strValue = '';
if (document.defaultView && document.defaultView.getComputedStyle) strValue = document.defaultView.getComputedStyle(oElm, '').getPropertyValue(strCssRule);
else if (oElm.currentStyle){
strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){ return p1.toUpperCase(); });
strValue = oElm.currentStyle[strCssRule];
}
return strValue;
}
//usage
getStyle(document.getElementById('slide-up'), 'padding-top');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment