W
weston
I could swear that I've done this before, but suddenly, I seem to be
unable to retrieve the values of CSS properties via Javascript.
For example, take this document:
http://weston.canncentral.org/web_lab/fetching_css_props_via_js/testcase.html
The document is pretty simple. There's a div id'd as "maindiv". It's
got a few CSS properties set on it via an external stylesheet:
#maindiv {
margin: 5% auto;
width: 200px;
height: 200px;
text-align: center;
font-size: 16px;
font-family: arial;
font-weight: bold;
background-color: white;
}
And what I'd like to be able to do, is grab those properties (say, an
element's CSS-defined height) via javascript, using something like
this:
id = 'maindiv';
emt = document.getElementById(id);
emt_height = emt.style.height;
Except this doesn't seem to be working for me. If you click on the
positioned white div in the above document, and compare the source with
the produced output, you'll see what I mean.
Have I just been imagining that you can retrieve these settings, or is
there something I'm doing wrong in this case?
Thanks,
Weston
unable to retrieve the values of CSS properties via Javascript.
For example, take this document:
http://weston.canncentral.org/web_lab/fetching_css_props_via_js/testcase.html
The document is pretty simple. There's a div id'd as "maindiv". It's
got a few CSS properties set on it via an external stylesheet:
#maindiv {
margin: 5% auto;
width: 200px;
height: 200px;
text-align: center;
font-size: 16px;
font-family: arial;
font-weight: bold;
background-color: white;
}
And what I'd like to be able to do, is grab those properties (say, an
element's CSS-defined height) via javascript, using something like
this:
id = 'maindiv';
emt = document.getElementById(id);
emt_height = emt.style.height;
Except this doesn't seem to be working for me. If you click on the
positioned white div in the above document, and compare the source with
the produced output, you'll see what I mean.
Have I just been imagining that you can retrieve these settings, or is
there something I'm doing wrong in this case?
Thanks,
Weston