Created
December 2, 2014 18:11
-
-
Save bchumney/4155600bc4e7dcde1d49 to your computer and use it in GitHub Desktop.
Element Style Values with Plain JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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