knowing where a block element is within the client element?

Discussion in 'Javascript' started by Guest, Oct 9, 2007.

  1. Guest

    Guest 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
    Guest, Oct 9, 2007
    #1
    1. Advertising

  2. wrote:
    > 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
    --
    Prototype.js was written by people who don't know javascript for people
    who don't know javascript. People who don't know javascript are not
    the best source of advice on designing systems that use javascript.
    -- Richard Cornford, cljs, <f806at$ail$1$>
    Thomas 'PointedEars' Lahn, Oct 9, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Woolly Mittens
    Replies:
    8
    Views:
    423
    Woolly Mittens
    Sep 22, 2003
  2. Noozer

    Block DIV within a block DIV?

    Noozer, Jan 6, 2005, in forum: HTML
    Replies:
    3
    Views:
    11,349
    Mitja
    Jan 6, 2005
  3. morrell
    Replies:
    1
    Views:
    936
    roy axenov
    Oct 10, 2006
  4. Thufir
    Replies:
    1
    Views:
    125
    7stud --
    Oct 20, 2007
  5. Jari Williamsson

    Delete array element within iterator block?

    Jari Williamsson, Nov 30, 2007, in forum: Ruby
    Replies:
    3
    Views:
    252
    Jari Williamsson
    Nov 30, 2007
Loading...

Share This Page