4

Is it possible to trigger double click on user's single click? note that I want the same behaviour as it was double clicked by using mouse, Is it possible to get the same behaviour using jQuery? What I've tried so far :

$("#container").dblclick(function() { 
    //code executed on jQuery double click rather than mouse double click
});
$("#container").click(function() { 
    $(this).dblclick(); 
});

When I double click using mouse it goes right, it generate the right result I want, but when I try to do it with jQuery, it does not seem to be working, please Help! Thanks in Advance :)

3
  • 2
    Why not just put the logic in an external function and call that function from both event handlers? I'm at a loss to understand why you'd want to always trigger a double click on a single click, though Commented Aug 2, 2016 at 15:00
  • 1
    @RoryMcCrossan, sometimes you are using a 3rd party module and you want to trigger events on elements that created by that module. Commented Aug 2, 2016 at 15:08
  • 1
    What is the behaviour of mouse double click you are talking about? Share a minimalistic sample replicating your issue Commented Aug 2, 2016 at 15:08

2 Answers 2

6

Not sure where exactly your problem is, but this code works exactly as expected:

$("#container").dblclick(function() { 
  //code executed on jQuery double click rather than mouse double click
  alert('dblclick');
});
$("#container").click(function() { 
  alert('click');
  $(this).dblclick(); 
});

$("#container2").click(function() { 
  $("#container").click();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="container">click 1</div>
<div id="container2">click 2</div>

If you click on 'click 1' - you will have the 2 alerts (the original and the dblclick).
If you click on 'click 2' - the jquery will trigger the click on the first element, which will trigger 2 alerts (the click and the dblclick).

Sign up to request clarification or add additional context in comments.

Comments

0

Just an update on why. I use agent ransack and if I can launch it with a double-click I get two instances of the program. I can use different search parameters on each.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.