0

Is there any way to make double click programmatically something like

 document.querySelector("button").blur()

but for double click, because document.querySelector("button").dblclick() isnt working...

Thank you.

4
  • Have you checked the browser console for errors? Commented Sep 7, 2017 at 8:24
  • same sort of question has been posted please try that stackoverflow.com/questions/38723960/… Commented Sep 7, 2017 at 8:25
  • @TharikKanaka apart from jQuery isn't tagged in this question and the one you have posted is using jQuery Commented Sep 7, 2017 at 8:27
  • @NewToJS document.querySelector(...).dblclick is not a function Commented Sep 7, 2017 at 8:29

2 Answers 2

0

Try this to emit double click event:

var dbclickEvent = new MouseEvent('dblclick', {
   bubble: true,
   view: window
})

document.querySelector('button').dispatchEvent(dbclickEvent)
Sign up to request clarification or add additional context in comments.

Comments

-1

One useful method of event is the preventDefault() method. preventDefault() will prevent whatever the browser would have done automatically when, say, a double click occurred.

 var button= document.querySelector('button');
 button.addEventListener('dblclick', function(event){
event.preventDefault();
},false);

5 Comments

Are you going to explain your answer or do you plan to just dump the source code and hope the OP does some research to understand what is happening within your source code? Although the source code might be good, answers like this can still be down voted for not being detailed/explained as it isn't very helpful to some who might want to use it....
I am also self-taught but I also ensure I have a clear understanding of the functions/source code I use before putting it to use, especially if I am to suggest it to someone else as that person just might want to know the benefits of using it and how it works.
Your source code is incorrect and your explanation has a spelling mistake. Please take your time to plan and write your answer. Spelling: preventDefualt() and the source code error: You never close the function within the event listener }.
I see you have updated your answer but the spelling mistake is still in the description and you have placed the } in the wrong place so the source code is also still incorrect.
Now it is ok I think that , I use my iPhone so there were errors in the code and explanation, I hope that it will be good and working code

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.