As Mozilla states on the TouchEvent page:
The event's target is the same element that received the touchstart event corresponding to the touch point, even if the touch point has moved outside that element.
This is not the same as mousemove
and mouseup
, where the target really is the DOM element that the mouse is over.
What's the best way, without using any library, to get the element that my touchmove
or touchend
event occurs on?
As Mozilla states on the TouchEvent page:
The event's target is the same element that received the touchstart event corresponding to the touch point, even if the touch point has moved outside that element.
This is not the same as mousemove
and mouseup
, where the target really is the DOM element that the mouse is over.
What's the best way, without using any library, to get the element that my touchmove
or touchend
event occurs on?
1 Answer
Reset to default 7Read the coordinates (pageX
and pageY
) from the event object. Then use document.elementFromPoint(x, y)
to get the top element at that position.