knowing where a block element is within the client element?

G

Guest

I am trying to identify how I can find out where a specific element (e.g. a
<div> or a <img> ) appears within a page. I want to position some else
immediately after the <element> and so need to know where it begins! I
can't use the x / y co-ordinates as this just tells me where the mouse is.

Can anyone help?


Thanks

James
 
T

Thomas 'PointedEars' Lahn

I am trying to identify how I can find out where a specific element (e.g. a
<div> or a <img> ) appears within a page. I want to position some else
immediately after the <element> and so need to know where it begins!

That's unlikely. The `div' or `img' element would then be have to be
positioned absolute or floating with CSS. If it was not positioned absolute
and not floating you could simply insert the new element node right after
the target element node:

if (target.nextSibling)
{
target.insertBefore(newElementNode, target.nextSibling);
}
else
{
target.parentNode.appendChild(newElementNode);
}

How you can obtain the `target' reference depends on your markup, and how
you can obtain the `newElementNode' reference depends on the element type
("tag name").
I can't use the x / y co-ordinates as this just tells me where the mouse is.

Parse error.
Can anyone help?

Finding out the rendering position of an element is not a trivial task (and,
from what I can see, probably way over your head) as there are many aspects
to watch for, including but not limited to different box models. If you
really need that (see above), you should search the archives for it, see
<http://jibbering.com/faq/> or acquire the necessary knowledge by reading
much more documentation than you did for this question.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top