Home / DHTML & CSS / Getting global and external style sheet values in DHTML |
|
CodingForums Jump to... |
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 |
http://www.javascriptkit.com
Copyright © 1997-2005 JavaScript Kit.
NO PART may be reproduced without author's permission.