Jquery creates a Double Click event on A Href

Guys, it's possible to create a double click event for href using jquery

+4
source share
2 answers

The problem with performing the action on double-clicking the anchor is that the page will be redirected on the first click, not allowing the double-click to respond on time.

If you want to "intercept" the click event so that the double-click event has a chance to fire before the page is redirected, you may need to set a timeout per click, as shown below:

$('a').click(function () { var href = $(this).attr('href'); // Redirect only after 500 milliseconds if (!$(this).data('timer')) { $(this).data('timer', setTimeout(function () { window.location = href; }, 500)); } return false; // Prevent default action (redirecting) }); $('a').dblclick(function () { clearTimeout($(this).data('timer')); $(this).data('timer', null); // Do something else on double click return false; }); 

Demo: http://jsfiddle.net/4788T/1/

+5
source

if link a has the identifier "id", then:

 $("#id").bind("dblclick", ....); 
0
source

Source: https://habr.com/ru/post/1337337/


All Articles