0

Hi i'm writing a plugin without JQuery .

On a single click the item.id is undefined and the link doesn't open. But after a second click the id is defined.

So i'm searching a workaround to make the mouse double click on a single click when clicking on this href link.

The div doesn't have a own default id.

Thanks for your help

Bregt
  • 3
  • 5
  • Does this answer your question? [How to programmatically fire a dblclick event defined with addEventListener?](https://stackoverflow.com/questions/18399215/how-to-programmatically-fire-a-dblclick-event-defined-with-addeventlistener) – Andam Dec 08 '21 at 16:37
  • i tried but it doesn't work, problem is that i don't have an id provided to the link. – Bregt Dec 13 '21 at 10:01
  • what does it have then? how do you recognize this div? is it by class, data attribute, tagname, position of the div .. – Andam Dec 13 '21 at 12:38
  • db2un_Fri Oct 18 16_38_15 2019.log – Bregt Dec 13 '21 at 15:08
  • I have added an answer to solve your issue – Andam Dec 13 '21 at 16:33

1 Answers1

0

This code triggers double click for every a tag that has a class of anchorLink when you singe click on them

I have explained it row by row in the code with comments on how it works

// Creating an event for double click (dblclick)
var event = new MouseEvent('dblclick', {
  'view': window,
  'bubbles': true,
  'cancelable': true
});

// get every a tag with class anchorLink and loop through them
document.querySelectorAll("a.anchorLink").forEach(anchorLink => {
  // add click event to it
  anchorLink.addEventListener('click', function (e) {
    // trigger double click event we created at top
    anchorLink.dispatchEvent(event);
  });
  
  // This is just to show that it triggers double click by single clicking
  // You dont need from here
  anchorLink.addEventListener('dblclick', function (e) {
    console.log(e.target.innerText);
  });
  //to here
  //
});
<a class="anchorLink" href="#" title="db2un_Fri Oct 18 16_38_15 2019.log" data-dojo-attach-point="linkColumnAnchor">db2un_Fri Oct 18 16_38_15 2019.log</a>
<br>
<a class="anchorLink" href="#" title="db2un_Fri Oct 18 16_38_15 2020.log" data-dojo-attach-point="linkColumnAnchor">db2un_Fri Oct 18 16_38_15 2020.log</a>
Andam
  • 2,087
  • 1
  • 8
  • 21