Forum Moderators: not2easy

Message Too Old, No Replies

CSS Property values not accessible

Cannot seem to access an object's default properties.

         

dnimrodx

3:04 pm on Jan 29, 2004 (gmt 0)

10+ Year Member



Hello!

I have posted this yesterday in the HTML and Browsers forum section and noone has yet replied back. Could you please take a look at this?

Okay then... in a Javascript Reference Manual I found the following:

(...)
From a scripting point of view, it is important to know that while a style object's property exhibits a default behaviour (a font size or alignment), the default value may not be reflected in the property unless the value has been explicitly set in the element tag's STYLE
(...)

So, admiting I use something like:


<style type="text/css">

#sample_id
{
position:absolute;
left:167px;
top:373px;
width:144px;
height:61px;
}

</style>

</head>

<script type="text/javascript" language="javascript">

function onWindowResize()
{
// myValue will be set to zero because the property cannot be accessed as it was not initialized inside the style clause (?)
var myValue = document.all.sample_id.style.pixelTop
}

</script>

<div id="sample_id">
<img src="images/bkg_01.jpg" width="231" height="234">
</div>

... this means I won't be able to access sample_id's property values in the script above because its properties were not initialized in the style clause, inside the <DIV> tag.

Does anyone know if there is a logical reason for this to work this way? I feel this is very annoying and somewhat illogic, does anyone feel the same way as me?

What I would like to know is if there is a way of accessing the tag's properties without having to initialize them in the style clause.

Any suggestions?
Thank you a lot for your time! 8 )

D#Nimrod

BlobFisk

4:20 pm on Jan 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi dnimrodx,

Well, this sounds incorrect to me! I have loads of scripts where a style rule is in an external CSS file and I'm using javascript to manipulate it. Perhaps it means that if one wants to (say) toggle the visibility of a layer, the style rules for that layer must include a visibility: style?

Are the code snippets in your post above something that you are working on? Is that the complete javascript function?

dnimrodx

5:15 pm on Jan 29, 2004 (gmt 0)

10+ Year Member



First of all I feel I must thank you, BlobFisk, for having shown interest in my post.

Well let me try to answer your questions and therefore make you understand what's happening... 8 )

Are the code snippets in your post above something that you are working on?

I am creating a website which must have the body content vertically centered. Therefore, being something I have never been asked to do, I thought of using the onResize event in the BODY tag and work the coordinates out in javascript...

As I was not able to gain access to the styles' properies (not even one of them) I wrote a kind of a test code (similar to that one above) to try and figure out what the problem is.

I have not slept for 2 days now, (only had 1 1/2 hours to sleep), I am working simultaneously with 3 projects (included this one), two of which in C++... it feels like my head is about to explode. You know how it's like when you have deadlines. : )

Any suggestions about what it could be related to?
Again thanks, BlobFisk 8 )

d#Nimrod

BlobFisk

5:52 pm on Jan 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




I am creating a website which must have the body content vertically centered.

Do you know the exact dimensions of the layer you wish to center? If so, why not just determine the availheight and use that to determine yout top:?

HTH

BYW, get some sleep! ;)

dnimrodx

10:10 pm on Jan 29, 2004 (gmt 0)

10+ Year Member



Hi! I am back again... just after I had 2 hours of sleep or so. Feel better anyway.

Do you know the exact dimensions of the layer you wish to center? If so, why not just determine the availheight and use that to determine yout top:?

Well I could determine the availheight and use it to determine the top: as the page has been conceived in Photoshop. But I don't know when I will have a non fixed height page in my hands to build/work with and therefore I had to know how to access the style's properties - it has become more of a challenge, really! : )

Thanks BlobFisk!

d#Nimrod