Home / DHTML & CSS / Getting global and external style sheet values in DHTML


 

CodingForums
Having trouble with scripting? Visit our help forum to get the answers you need.

Jump to...
-Free JavaScripts
-JS tutorials
-JS Reference
-DHTML/CSS

-Free applets
-Web Tutorials
-Link to Us!


Getting global and external style sheet values in IE5+

First stop- retrieving global and external CSS property values in IE5+. The key to the process is the "currrentStyle" object, which returns the cascaded value of properties, in other words, what we want! Here's a working example:

<head>
<style type="text/css">
#test{
width: 100px;
height: 80px;
background-color: yellow;
}
</style>
</head>

<body>
<div id="test">This is some text</div>

<script type="text/javascript">

var mydiv=document.getElementById("test")
alert(mydiv.currentStyle.width) //alerts "100px"
alert(mydiv.currentStyle.backgroundColor) //alerts "yellow"

</script>
</body>

By using the "currentStyle" property, the browser returns the cascaded value of the CSS property specified, which includes values specified using either global or external style sheets.

-Tutorial introduction
-Getting global and external style sheet values in IE5+
-Getting global and external style sheet values in NS6+
-Cross browser function for retrieving global/external CSS properties

Getting global and external style sheet values in NS6+

http://www.javascriptkit.com
Copyright © 1997-2005 JavaScript Kit. NO PART may be reproduced without author's permission.