Velocity Reviews > How to find what control is in some position?

# How to find what control is in some position?

jkarpago
Guest
Posts: n/a

 04-01-2006
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.

Thanks so much.

Thomas 'PointedEars' Lahn
Guest
Posts: n/a

 04-01-2006
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

VK
Guest
Posts: n/a

 04-01-2006

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.

jkarpago
Guest
Posts: n/a

 04-03-2006
Thanks for your help. Thatīs what I imagine, but I wanted to know if
there was another solution.
Thanks so much