|
-
Aug 8th, 2002, 12:22 PM
#1
Thread Starter
Hyperactive Member
is there a way around this
if I have a layer say
<style>
#lay1 { position:absolute; width:200px; etc...}
</style>
and then I want to perform an action based on the values of width of lay1
i thought you can just pass the value to a simple data type
like this
var widthOflayer;
widthOflayer = document.GetElementById("lay1").style.width;
alert("Value is " + widthOfLayer);
I was told that this does not work because that property is not
initialized;
I was hoping that it would be able to see that I did initialize it by specifying the width to be 200px (in the <style> tags)
in other words I need to do this
document.GetElementById("lay1").style.width = 200
var widthOflayer;
widthOflayer = document.GetElementById("lay1").style.width;
alert("Value is " + widthOfLayer);
which to be makes no sense..
is there a way around this?
i get the same result with string values such style.backgroundColor for ex.
bsw2112
-
Aug 8th, 2002, 01:56 PM
#2
Black Cat
This was on the Mozilla site:
W3C DOM2 Reflection of an Element's CSS Properties
See the W3C DOM2 Working Draft (work in progress) section 4.4, Extensions to Level 1 Interfaces. Keep in mind that according to this working draft, the values returned by the style property of an element reflect static settings in the element's STYLE attribute only, not the total "computed style" that includes any inherited style settings from parent elements. Therefore, if you wish to read and write these properties from JavaScript through the DOM2, use one of these two approaches:
* Place all of the element's static CSS declarations (if it has any) in the element's STYLE attribute.
* Use no static CSS declarations for the element, and initialize its CSS properties from JavaScript through the DOM.
Josh
Get these: Mozilla Opera OpenBSD
I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.
-
Aug 8th, 2002, 02:13 PM
#3
Thread Starter
Hyperactive Member
Hi Josh,
When you talk about static in this case,
do you mean define all attributes in <style> tags
that you will not change and for
the rest perform assignments through javascript?
or
just fill in all attributes with onLoad event so I can then change any of them at will.
I am getting confused with the meaning of static...
I know in c++ you can make static variables that preserve their
scope even when the function they are part of is finished.
void hello()
{
static int numOfTimesFunctionIsCalled = 0;
numOfTimesFunctionIsCalled++;
cout<<"you called me again. It is not the <<numOfTimesFunctionIsCalled<<"time\n";
}
perhaps when I will read that w3c article all will make sense 
thanks
bsw2112
-
Aug 8th, 2002, 03:25 PM
#4
Black Cat
Static, in the quote above (written by the Mozilla people, not me), means the style is hard coded into the web page, using <style>div {width:50%;}</style> or <div style="width:250px">. It's saying the DOM doesn't know what the style is unless it was you explicitly set it, it doesn't attempt to figure it out for itself.
Josh
Get these: Mozilla Opera OpenBSD
I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|