Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery How to distinguish click() and dblcick() for a DIV element?

If I subscribe dblclick() and click() for a DIV element and make double click by mouse on the DIV, the click() handler calls first before dblclick() is called. How to avoid handling click() before the dblclick()?

UPDATE: The question has already asked before Prevent click event from firing when dblclick event fires. But here are good answers too.

like image 501
despero Avatar asked Aug 26 '10 13:08

despero


People also ask

How can I tell if a div is clicked?

To check if an element was clicked, add a click event listener to the element, e.g. button. addEventListener('click', function handleClick() {}) . The click event is dispatched every time the element is clicked. Here is the HTML for the examples in this article.

How can you tell the difference between single click and double click?

Typically, a single click initiates a user interface action and a double-click extends the action. For example, one click usually selects an item, and a double-click edits the selected item.

Can you give a Div an onClick?

To set an onClick listener on a div element in React:Set the onClick prop on the div. The function you pass to the prop will get called every time the div is clicked. You can access the div as event. currentTarget .

How does jQuery detect right click?

Using the mousedown() method: The mousedown() method in jQuery can be used to bind an event handler to the default 'mousedown' JavaScript event. This can be used to trigger an event. The event object's 'which' property can then used to check the respective mouse button.


1 Answers

Try this: http://jsfiddle.net/DAgyC/ It implements an timeout after the first click, if there is a double-click, the first click is ignored.

like image 124
chriszero Avatar answered Nov 15 '22 04:11

chriszero