Peter Michaux wrote:
Hi,
Since I can do this
document.defaul tView.getComput edStyle(el, null).height;
why would I ever want to do this
document.defaul tView.getComput edStyle(el,
null).getProper tyValue('height ');
The first syntax requires property name in camelCase; the second syntax
takes property name as it is. This way it could be possible to choose
the most convenient way for a particular situation w/o normalizing all
involved names. But as IE currentStyle takes only camelCase anyway, the
second syntax didn't go into wide use.
Also please note that as you are asking for *computed* (current) style,
you are getting normalized value back (how is it internally stored by
UA, so not necessarily how it is indicated in the source). For the
second reason the whole getComputedStyl e interface is used only rather
occasionally for specific tasks - yet for these tasks it is very
useful.
// See the sample:
<html>
<head>
<title>Styles </title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<style type="text/css">
body {
color: #000000;
background-color: #FFFFFF;
}
h1 {
background-color: yellow;
}
</style>
<script type="text/javascript">
function init() {
var header = document.getEle mentsByTagName( 'h1')[0];
if ((document.defa ultView)
&& (document.defau ltView.getCompu tedStyle)) {
window.alert(do cument.defaultV iew
.getComputedSty le(header,null) .backgroundColo r);
window.alert(do cument.defaultV iew
.getComputedSty le(header,null)
.getPropertyVal ue('background-color'));
}
else if (header.current Style) {
window.alert(he ader.currentSty le.backgroundCo lor);
}
}
window.onload = init;
</script>
</head>
<body>
<h1>Lorem ipsum</h1>
</body>
</html>