0

I have been using the Javascript events touchstart and touchmove on iOS. The documentation specify that instances of the TouchEvent object should have arrays of Touches stored in TouchEvent.touches, TouchEvent.targetTouches, TouchEvent.changedTouches...

On iOS, it seems that this isn't the case. For instance, this piece of code, when a touchmove events happens, shows an alert box containing 'undefined':

$('input[range]').bind('touchmove', function(event) {
  alert(typeof event.touches);
});

Though the event is properly handled, the object passed as a parameter doesn't fit the W3C documentation (http://www.w3.org/TR/touch-events/), not even Apple's own documentation (https://developer.apple.com/library/ios/documentation/appleapplications/reference/safariwebcontent/HandlingEvents/HandlingEvents.html).

Why is that ? How is that ? How do I get the details for my touch events ?

user3387633
  • 121
  • 11
  • You do understand that `event` represents a custom jQuery event object, not the original, right? (http://api.jquery.com/category/events/event-object/) You could try `event.originalEvent.touches` – Ian Jul 07 '14 at 16:36
  • No, I do not understand that. I was just reading an approved response from another question that was saying the exact opposite. I'll have to correct them. (the question: http://stackoverflow.com/questions/4755505/how-to-recognize-touch-events-using-jquery-in-safari-for-ipad-is-it-possible) – user3387633 Jul 07 '14 at 16:37
  • I don't see anything incorrect on that page. You are using **jQuery**. Things don't match up perfectly/closely to native JavaScript. An event handler in jQuery (using `.bind()`, `.on()`, `.live()`, etc.) does not necessarily syntactically map to things like `document.addEventListener` - the concepts are the same though. Like I said, jQuery wraps the event object with common, normalized values, like what it lists in the link I provided (`touches` is not common to events). It also provides a way to access the actual original event (`event.originalEvent`) – Ian Jul 07 '14 at 16:46
  • And actually, the only jQuery-only answer in the link you provided has a comment that says "You'll find the touches info under `ev.originalEvent`" – Ian Jul 07 '14 at 16:47

0 Answers0