0

My website has a button that works after double click but it seems that users don't know that it works on double click, therefore they don't click it two times. Is there any javascript or jquery method that automatically double clicks at specific location after single is done ? Thanks for your answers

robinton
  • 75
  • 5
  • 14
  • possible duplicate of [Triggering double click via jQuery or pure Javascript for a single click event](http://stackoverflow.com/questions/6648264/triggering-double-click-via-jquery-or-pure-javascript-for-a-single-click-event) – Michal Jan 03 '14 at 06:57
  • possible duplicate of [highlight text on single click (javascript jquery html)](http://stackoverflow.com/questions/9657937/highlight-text-on-single-click-javascript-jquery-html) – Ja͢ck Jan 03 '14 at 07:01
  • Why don't you listen for just the single click? A double click has a single click as well. – Ja͢ck Jan 03 '14 at 07:19

3 Answers3

1

Try to trigger double click within the click event.

$('selector').on('click', function () {
    $(this).trigger('dblclick');
});

But I feel that if they double click it, then dblclick will be executed twice. Instead try to show some messages like "double click to get it worked" inorder to show users.

From @James Allardice's answer,

it seems that there is going to be no reliable way to determine whether the user intended a double click or two single clicks, but if you want to try, you could perhaps use setTimeout in a click event handler to see if another click occurs within a certain period of time.

If you still need to have this, then go for @Paolo Bergantino's hack.

Community
  • 1
  • 1
Praveen
  • 55,303
  • 33
  • 133
  • 164
  • But i need double click at specific position. your answer will just click double at element id – robinton Jan 03 '14 at 07:12
  • @robinton how do I know about your HTML elements? you haven't posted here. In general `selector` represent id, class and elements. Hence I posted a general approach :) – Praveen Jan 03 '14 at 07:14
0

You can Use:

$('#id/.class').click(function(){
$(this).dblclick(); 
});

Working Fiddle

Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
  • what happens if the you double click the button? it show 2 times the alert. which is not the exact behavior. – Praveen Jan 03 '14 at 07:06
  • @PraveenJeganathan:you should be using other element like div instead of button. – Milind Anantwar Jan 03 '14 at 07:12
  • No whatever element, when you trigger `dblclick` it will be executed twice. check this fiddle http://jsfiddle.net/YbPG5/1/ to get more understanding – Praveen Jan 03 '14 at 07:17
  • I already found that hack and given as a reference in my [answer](http://stackoverflow.com/a/20898288/1671639) ;) – Praveen Jan 03 '14 at 07:27
0
$( "#your_tag_id" ).click(function() {
   $( "#your_tag_id" ).dblclick();
});
Awlad Liton
  • 9,366
  • 2
  • 27
  • 53