0

I am working on writing a script on browser web pages. I need to trigger right click event or a long press event on an HTML element.

I have figured out how to click on an element through the click() method. But now i need to trigger a right click or a long press.

Here is the code:

 let div = document.querySelector(".scrollViewport");
    let chats = div.children[0].children[0].children;
    chats[index].children[0].children[0].click();

Any help? Thanks,

Bilal Shah
  • 79
  • 4
  • 1
    This is two questions in one. Right click simulate in JS https://stackoverflow.com/questions/7914684/trigger-right-click-using-pure-javascript - Simulate long click in JS https://stackoverflow.com/questions/28664703/simulate-long-press-in-javascript – evolutionxbox Sep 07 '20 at 11:48
  • Does this make sense? – evolutionxbox Sep 07 '20 at 13:07
  • The first answer doesn't work for me. The second one just seems to be a listener for a long press event. not a way to trigger the event. – Bilal Shah Sep 08 '20 at 14:45
  • Huh? The first answer is how you fire a click event in JS. --- The second isn't a listener, but how to emulate a long click. --- Both of these are what you've asked about. --- If something "doesn't work" consider asking a question just about that. – evolutionxbox Sep 08 '20 at 15:29

0 Answers0