Shabbb Shabbb - 6 months ago 17
Javascript Question

Identify event that triggered the function

How can I get the event that triggered a function using jQuery?

$(document).on("click touchstart", "#element", function() {
if( EVENT IS TOUCHSTART ) {
// DO THIS SINCE EVENT WAS TOUCHSTART
}
});

Answer

There is type property for events

$(document).on("click touchstart", "#element", function(event) {
  if(event.type == "touchstart") {
     // DO THIS SINCE EVENT WAS TOUCHSTART
  }
});
Comments