Full version: jsB@nk » Snippet » getStyle
URL: https://www.javascriptbank.com/getstyle.html
Use this JavaScript snippet to get the rendered style of an element. Quick and simple to implement.
Full version: jsB@nk » Snippet » getStyle
URL: https://www.javascriptbank.com/getstyle.html
<script language="javascript">// Created by: Robert Nyman :: http://www.robertnyman.com//* Example call of the function: getStyle(document.getElementById("container"), "font-size");*/// The regular versionfunction 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 whatsoeverfunction 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;}</script><!-- This script downloaded from www.JavaScriptBank.com Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->
<p align=center id=demo style="text-align: center;">JavaScriptBank.com</p><script>alert(getStyle(document.getElementById("demo"),7));</script><!-- This script downloaded from www.JavaScriptBank.com Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->