Pajar Fathurrahman Pajar Fathurrahman - 4 months ago 18
jQuery Question

Double click / tap event cross browser and device

I try use dblclick event like this

$(element).on('dblclick', function(){
//handler
)};


but just working for double click not for double tap.
I need some jquery/javascript function for handle double click/tap event, i need for touchscreen laptop, someone can help me with a snippet or anything?

Answer

Using jQuery:

This should get you started:

var divdbl = $("div:first");
divdbl.dblclick(function() {
  divdbl.toggleClass("dbl");
});
div {
  background: blue;
  color: white;
  height: 100px;
  width: 150px;
}

div.dbl {
  background: yellow;
  color: black;
}
<!doctype html>
<html lang="en">
<head>
  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
 
<div></div>
<span>Double click the block</span>
 
</body>
</html>

More info here.