As the touchend
event is bind to the element where the touchstart
is fired, how can I get the element at the position where the finger leaves, when this is outside of the element where the event was binded to.
Asked
Active
Viewed 4,881 times
16

niksvp
- 5,545
- 2
- 24
- 41

Andreas Köberle
- 106,652
- 57
- 273
- 297
1 Answers
18
You could use the document.elementFromPoint
method, passing it the coordinates of the event:
$('#element').on("touchend",function(event){
var endTarget = document.elementFromPoint(
event.originalEvent.touches[0].pageX,
event.originalEvent.touches[0].pageY
);
});
EDIT: Found some good article about getting elements at specific coordinates. http://www.zehnet.de/2010/11/19/document-elementfrompoint-a-jquery-solution/

Armel Larcier
- 15,747
- 7
- 68
- 89
-
2It seems to work, but I have to use `event.changedTouches[0].pageX` to get the coordinates. Is cause of testing in chrome with emulated touch events? – Andreas Köberle Sep 26 '12 at 07:52
-
This fails for an element that is `position:fixed` and has (statically positioned) elements underneath. – Coby May 22 '13 at 22:20
-
I need this on multitouch - would like to know which if the touches[] has ended – Fanky Feb 25 '18 at 22:10
-
On mobile Safari, `originalEvent.touches` seems to be an empty list on `touchend`. Only on `touchstart` does it contain a `Touch` object. – Jo Liss Mar 03 '23 at 15:05