Can't get touchstart event properties?

When I try to implement the code below:

$('.touchelement').bind({'touchstart':function(e){
    console.info(e.touches.item(0));
}});

It shows the result as undefined. Not only in touchstart, but for any other event, such as (touchmove, touchhend), it shows the same result.

Is there any alternative way to bind a touchstart event using jquery.

+3
source share
2 answers

jQuery does some processing of the event objects to make them consistent between browsers, but it does not know about the array touches, so it is not copied to the new event object. So you need to access it through the original event object, which event.originalEvent.

$('.touchelement').bind({'touchstart':function(e){
  console.info(e.originalEvent.touches[0]);
}});
+18
source

?

$('.touchelement').bind('touchstart', function(e){
  console.info(e.touches);
});
0

All Articles