Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery touchstart event not working in iphone

Tags:

jquery

I am trying like this and its not working in iphone

$(document).bind('touchstart',function(){
    alert('hello');
});

but its working like this

document.addEventListener('touchstart', function(){
    alert('hello');
}, false);

how to get touchstart event working with jquery?

Its working with

$(document).on('touchstart', function(e){
            //e.preventDefault();
            var touch = e.touches[0] || e.changedTouches[0];
        });

but getting error e.touches is not an object

like image 676
coure2011 Avatar asked Feb 02 '23 08:02

coure2011


1 Answers

To get the touches property you can use e.originalEvent:

$(document).on('touchstart', function(e){
  var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
});
like image 118
bjornd Avatar answered Feb 11 '23 06:02

bjornd