Here's a simple example of the problem I have:
I have had several occasions where I had to return the value contained in the CSS definition for the tag (ie. eg1), and could not, so had to resort to doing eg2, which is quite obviously very annoying.
I thought eg3 should work as well, but was surprised to find it didn't either.
This example problem I've replicated in IE6PC and Mozilla1.4PC to ensure you inquisitive types can replicate the issue.
Can anybody help me?
Code:
<html>
<head>
<title></title>
<style>
div#eg1 { background-color: red; }
</style>
<link href="./eg3.css" rel="STYLESHEET"></link>
<!-- div#eg3 { background-color: orange; } -->
</head>
<body>
<div id="eg1">1.
<script>
document.write("'" + document.getElementById('eg1').style.backgroundColor + "'");
</script>
</div>
<div id="eg2" style="background-color: yellow;">2.
<script>
document.write("'" + document.getElementById('eg2').style.backgroundColor + "'");
</script>
</div>
<div id="eg3">3.
<script>
var chk = (document.styleSheets[0].cssRules)? document.styleSheets[0].cssRules : document.styleSheets[0].rules
document.write("'" + chk[0].style.color + "'");
</script>
</div>
</body>
</html>
I have had several occasions where I had to return the value contained in the CSS definition for the tag (ie. eg1), and could not, so had to resort to doing eg2, which is quite obviously very annoying.
I thought eg3 should work as well, but was surprised to find it didn't either.
This example problem I've replicated in IE6PC and Mozilla1.4PC to ensure you inquisitive types can replicate the issue.
Can anybody help me?