Created
November 15, 2012 01:44
-
-
Save zhuzhuaicoding/4076125 to your computer and use it in GitHub Desktop.
getStyle
This file contains hidden or 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
| /* | |
| Example call of the function: | |
| getStyle(document.getElementById("container"), "font-size"); | |
| */ | |
| // The regular version | |
| 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; | |
| } | |
| // The version if you expect any IE 5.0 users whatsoever | |
| function getStyle(oElm, strCssRule){ | |
| var strValue = ""; | |
| if(document.defaultView && document.defaultView.getComputedStyle){ | |
| strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule); | |
| } | |
| else if(oElm.currentStyle){ | |
| try{ | |
| strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){ | |
| return p1.toUpperCase(); | |
| }); | |
| strValue = oElm.currentStyle[strCssRule]; | |
| } | |
| catch(e){ | |
| // Used to prevent an error in IE 5.0 | |
| } | |
| } | |
| return strValue; | |
| } | |
| 72.47.228.190 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://robertnyman.com/2006/04/24/get-the-rendered-style-of-an-element/