Guys is it possible to create double click event for the a href using jquery
Asked
Active
Viewed 5,428 times
2 Answers
5
The problem with performing an action on double click of an anchor is that the page will redirect on the first click, preventing the double click from responding in time.
If you want to "intercept" the click event so that the double click event has a chance to fire before the page redirects, then you may have to set a timeout on the click like this:
$('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;
});

David Tang
- 92,262
- 30
- 167
- 149
-
thanks using this can i assign a href with diffrent id with same function and different parameters. – Dead Programmer Jan 27 '11 at 16:09
-
in chrome this does not work. used only click trigger, and timer to see whether a second click came in to make it a double click – cc young May 18 '12 at 12:04
-
works in Chrome now, apparently - http://jsfiddle.net/jaspermogg/pFyNY/5/ - double click on the `a`s in the 'result' box to edit, or single click to visit. Thanks @Box9 for this - it's awesome! – Jasper Mogg Jun 22 '12 at 16:53
0
if you a
link has id of "id", then:
$("#id").bind("dblclick", ....);

Kris Ivanov
- 10,476
- 1
- 24
- 35
-
and Yes, A tag does support double-click, http://www.w3schools.com/tags/tag_a.asp, I guess you have to be really fast to do it, I do not recommend it – Kris Ivanov Jan 27 '11 at 15:16