Asif Iqbal
Asif Iqbal

Reputation: 543

How to detect touchstart and click events and apply css accordingly

var myVideo = document.getElementById('myVideo');
var deviceAgent = navigator.userAgent.toLowerCase();
var event = deviceAgent.match(/(iphone|ipod|ipad)/) ? 'touchstart' : 'click';

$(document).on(event, '.mejs-fullscreen-button', function () {
if (event == 'click') {
  //here it cant catch click event
}//end of click
else {

}//end of touchstart
});

how to correctly map here when click or touchstart event starts? if(event=='click') does not work in window browsers any other way to write it?

Upvotes: 0

Views: 109

Answers (1)

Felix
Felix

Reputation: 38112

You need to pass event to your function as well as using event.type instead:

$(document).on(event, '.mejs-fullscreen-button', function (event) {
    if (event.type == 'click') {
        //here it cant catch click event
    }//end of click
    else {

    }//end of touchstart
});

Upvotes: 1

Related Questions