Forum Moderators: open

Message Too Old, No Replies

Wrong offsetLeft offsetTop position in MSIE

I use this to insert by javascript additional content

         

jetteroheller

8:43 am on Nov 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



At the end of a directory, I have the element

dem stands for directory end marker

<span id=dem></span>

The only reason for this element is,
that javascript can find out where the last element
of the directory is and decide to insert something or not

<div id=directory1>
Here comes entry 1<br>
Here comes entry 2<br>
Here comes entry 3<br>
<span id=dem1></span>
</div>

Here works all fine.

But at an other directory

<div id=directory2>
Here comes entry 1 &nbsp;
Here comes entry 2 &nbsp;
Here comes entry 3 &nbsp;
<span id=dem2></span>
</div>

The position of the end marker in MSIE 7 is 0,0
Firefox shows the correct position

Now I tested little bit changed

<div id=directory2>
Here comes entry 1 &nbsp;
Here comes entry 2 &nbsp;
Here comes entry 3 &nbsp;
<span id=dem2>TEST ENDMARKER</span>
</div>

Now suddenly MSIE 7 shows the correct position of the end maker

<div id=directory2>
Here comes entry 1 &nbsp;
Here comes entry 2 &nbsp;
Here comes entry 3 &nbsp; <BR>
<span id=dem2></span>
</div>

Also here correct position of the end marker

So I found out the following condition for
the error in MSIE 7 to show a wrong end marker position

if there is no previous <br> element in the parent
if there is nothing printable in the object

the postion is wrongly reported with

offsetTop=0
offsetLeft=0

g1smd

6:17 pm on Nov 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I would be wrapping each separate entry in a paragraph tag (and the whole lot contained within the div), so that there are no anonymous blocks to consider.

Have you examined the box model rendering using the Firebug for Firefox extension? That extension is an absolute revelation for many HTML and CSS matters.