Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery .on with doubleclick event

Tags:

jquery

Why would this work :

$(document).on("dblclick", "#areaA tr:has(td)", function(e) {      //code here  }); 

and this does not

$("#areaA tr:has(td)").on('dblclick', function(e) {     //Code here }); 

I'm following the example on the jquery documentation page exactly, but my double click does not fire. When I do it the first way, it works, but seems like it fires the event twice.

This is in the context of a Kendo UI grid.

Is there really a difference between these two pieces of code?

like image 520
carlg Avatar asked Nov 29 '12 20:11

carlg


People also ask

Is there a double click event in JavaScript?

No it isn't. There is a dblclick event but no corresponding shortcut function.

How do you use Dblclick?

The dblclick event fires when a pointing device button (such as a mouse's primary button) is double-clicked; that is, when it's rapidly clicked twice on a single element within a very short span of time.

How do I disable double click event?

dblclick(function(e){ e. preventDefault(); }); }); Above jQuery code will disable double click event for all the controls on the webpage.

Which method is used to attach an event handler function to an HTML element on mouse double click?

The dblclick() method attaches an event handler function to an HTML element.


1 Answers

The main difference is that the condition in the first one will be checked each time you click. So if the element with id areaA or the tr or td inside is added dynamically, only the first one can work.

like image 91
Denys Séguret Avatar answered Sep 20 '22 00:09

Denys Séguret