K2xL
K2xL

Reputation: 10270

Translating touch events from Javascript to jQuery

I am using

window.addEventListener("touchstart", function(ev){
    console.log(ev.touches); // good
});

How can I translate this to jQuery? I've tried:

$(window).bind("touchstart",function(ev){
    console.log(ev.touches); // says ev.touches is undefined
}

Any ideas?

Upvotes: 35

Views: 133342

Answers (2)

Simon Arnold
Simon Arnold

Reputation: 16157

$(window).on("touchstart", function(ev) {
    var e = ev.originalEvent;
    console.log(e.touches);
});

I know it been asked a long time ago, but I thought a concrete example might help.

Upvotes: 45

Dan Davies Brackett
Dan Davies Brackett

Reputation: 10071

jQuery 'fixes up' events to account for browser differences. When it does so, you can always access the 'native' event with event.originalEvent (see the Special Properties subheading on this page).

Upvotes: 46

Related Questions