Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
10-13-2012, 02:01 PM #1
- Join Date
- Jul 2009
- Rutland (county), UK
- Thanked 0 Times in 0 Posts
CSS font-setting not carried thru to JScript code
Having looked at an utterly trivial problem for a couple hours with no resolution, I feel a complete fool and would be grateful if someone would point out what is wrong - I cannot see the wood for trees. (I have boiled the more complex real problem down to its core code).
- ID selector 'foo' is assigned a font-size in inline CSS.
- 'foo' is defined in the body as a DIV
- object element 'bar' is obtained by a getElementById (of 'foo') and it is being defined (i.e. is not null or undefined) - the first alert says so!
- if the commented-out line is uncommented, the second alert of 'bar.style.fontSize' correctly displays '4em'
- but if it remains commented out, nothing is diplayed. Why pls?
var bar = document.getElementById("foo");
alert(bar); // says 'bar' is an HTML Div element
//bar.style.fontSize = "4em" //if uncommented, the next alert says '4em'
alert(bar.style.fontSize);} // displays nothing!
10-14-2012, 05:44 AM #2
In generall, styles set via CSS are *NOT* seen by JS code using OBJECTREF.style.property
Only those set via an inline style (or via other JS code) are seen.
To find the CSS-given style, you must use other coding. Look here:
Be yourself. No one else is as qualified.
10-14-2012, 04:49 PM #3
There's a little problem with the computed style of font sizes, though - while IE will return the font size in the measurements in the css (in this case in em) firefox and Chrome actually compute its size and return that in px
Not that I'm offering a solution or anything. Just thought I'd point that out