user3006927
user3006927

Reputation: 476

Mobile Browser not recognizing click event

I'm trying to log an event object each time an element is clicked (doing this for debugging).

I am using this function:

$(window).on('click', function(e) {
    console.log(e);
});

This logs the click event on my desktop bowser; however, this doesn't log anything in the mobile consoles. Do mobile browsers not interpret click events as touch events?

Upvotes: 1

Views: 100

Answers (1)

Kevin Jantzer
Kevin Jantzer

Reputation: 9471

That's because mobile browsers have "touch" events.

You can capture both clicks and touches using:

$(window).on('click touchstart', function(e) {
    console.log(e);
});

Upvotes: 1

Related Questions