Forum Moderators: not2easy

Message Too Old, No Replies

CSS ID and reading position

why doesn't that work?

         

baton

1:23 pm on Nov 26, 2003 (gmt 0)

10+ Year Member



i create a DIV element with CSS ID specified. inside CSS ID there is position specified but i can not see it from javascript lateron.. i try to access it via eg. div1.style.left and get an empty string instead of value specified inside CSS ID definition. how to get it? when i copy the CSS ID definition into DIV tag's STYLE attribute everything works fine..

how shall it be?

eg.

<style>#id1{position:absolute; background-color: blue; width:10; left: 110; top: 40; height: 300; cursor: w-resize; z-index:10}</style>

<div id="id1" onmousedown="alert(this.style.left)">

...and when i click on that div i get alert with an empty string..

Birdman

1:45 pm on Nov 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello, I am currently racking my brain learning this DOM stuff. Perhaps try the following:

alert(getElementById(this).style.left)

or

alert(document.getElementById(this).style.left)

Of course it depends what browser you use too. A real pain.

photon

1:55 pm on Nov 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't know if it will solve your problem, but in CSS you have to include
px
(or
em
or
%
or ...) in your length attributes. For example
 width:10px; left: 110px; top: 40px; height: 300px;

baton

2:08 pm on Nov 26, 2003 (gmt 0)

10+ Year Member



hi there..

the problem here is not in a correct accessing style.left attribute - as this works and is correct BUT in the CSS ID handling in IE probably..
once more - if i copy the code from STYLE ID definition into DIV's STYLE attribute it works..
why?

DrDoc

3:24 pm on Nov 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try adding type="text/css" to your style tag

<style type="text/css">

And, yes, add the units (px) too ;)