How to find what control is in some position?

Discussion in 'Javascript' started by jkarpago, Apr 1, 2006.

  1. jkarpago

    jkarpago Guest

    Hi:
    I need to find what control is in some position given.
    I mean, if I give the values left: 200px and top 300px I need to know
    what control in the page is in that position, or if there is not any.
    Can anyone help me, please?

    Thanks so much.
    jkarpago, Apr 1, 2006
    #1
    1. Advertising

  2. jkarpago wrote:

    > I need to find what control is in some position given.
    > I mean, if I give the values left: 200px and top 300px I need to know
    > what control in the page is in that position, or if there is not any.


    You will need a bubbling event, then evaluate its event target in its event
    listener. If that target is the element on which you are listening for
    the event, none of its descendants handled it. Otherwise, the computed
    coordinates of the handling descendant indicate its location. This
    approach is efficient (AIUI, O(1)) but unprecise insofar that more than
    one element can be at that position, and only the topmost element this
    event applies to will be identified as event target.

    Another more precise approach is to compute the area each element covers,
    and then run a comparison for each element, in O(n).

    Bottom line:
    Describe what you are up to, not what you /think/ you need to know to do it.


    PointedEars
    Thomas 'PointedEars' Lahn, Apr 1, 2006
    #2
    1. Advertising

  3. jkarpago

    VK Guest

    jkarpago wrote:
    > Hi:
    > I need to find what control is in some position given.
    > I mean, if I give the values left: 200px and top 300px I need to know
    > what control in the page is in that position, or if there is not any.
    > Can anyone help me, please?
    >
    > Thanks so much.


    For IE use document.elementFromPoint(x,y) method.

    For the Co you need to dig it out manually as suggested.
    VK, Apr 1, 2006
    #3
  4. jkarpago

    jkarpago Guest

    Thanks for your help. That´s what I imagine, but I wanted to know if
    there was another solution.
    Thanks so much
    jkarpago, Apr 3, 2006
    #4
    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. Sundance Kid

    Find Position of control

    Sundance Kid, Jan 21, 2005, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    148
    Sundance Kid
    Jan 21, 2005
  2. James Wong
    Replies:
    4
    Views:
    492
    James Wong
    Jul 14, 2004
  3. Wybo Dekker
    Replies:
    1
    Views:
    350
    Yukihiro Matsumoto
    Nov 15, 2005
  4. vdvorkin
    Replies:
    0
    Views:
    398
    vdvorkin
    Feb 10, 2011
  5. vdvorkin
    Replies:
    3
    Views:
    806
    vdvorkin
    Feb 14, 2011
Loading...

Share This Page