1

I want to make an autoDoubleClick function by only javascript.Example:

    var btn = document.getElementById("btn");
    btn.addEventListener("double",function(e){
        alert("Some thing");
    });

when we call function

autoDoubleClick(btn) 

so it will auto double click. Can you give me some ideal ??? (only javascript no jquery)

Lucy
  • 21
  • 3
  • here is an answer : http://stackoverflow.com/questions/19479948/how-to-trigger-a-link-a-tag-with-double-click-instead-of-single-click – Carr Aug 11 '16 at 05:06
  • Are you trying to listen for a double click, or actually perform a double click? – Spencer D Aug 11 '16 at 05:09

1 Answers1

1

The event name is dblclick. For triggering the event you can use the HTMLElement.prototype.dispatchEvent method:

btn.dispatchEvent(new Event('dblclick'));
Ram
  • 143,282
  • 16
  • 168
  • 197
  • @Lucy What works on IE? :) That method is related to `addEventListener`. The method support on IE is similar to `addEventListener`. For supporting older versions of IE you can define helper functions. Here is a related question: http://stackoverflow.com/questions/17720431/javascript-dispatchevent-click-is-not-working-in-ie9-and-ie10 – Ram Aug 11 '16 at 05:26