Jim
Jim

Reputation: 1440

double click() HTML DOM method

I'm working on a chrome extension and I'm curious how to double click DOM

When I want to just 1 click I use this function

document.getElementById('foo').click();

But some elements on a website needs a double click to be triggered

So Is there any method to do that with javascript?

Upvotes: 0

Views: 1876

Answers (2)

Identity1
Identity1

Reputation: 1155

document.getElementById('foo').dblclick();

check .dblcick()

If that doesn't work then use dispatchEvent() to simulate something similar.

 var target = document.getElementById('foo');
 var dblClickEvent= document.createEvent('MouseEvents'); 
 dblClickEvent.initEvent ('dblclick', true, true); 
 targLink.dispatchEvent (dblClickEvent); 

Upvotes: 0

Anik Islam Abhi
Anik Islam Abhi

Reputation: 25352

Try like this

var event = new MouseEvent('dblclick', {
'view': window,
'bubbles': true,
'cancelable': true  });
document.getElementById("foo").dispatchEvent(event);

Upvotes: 3

Related Questions