Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

154
Views
Simulate hover then click to trigger the already set onclick function

In Gmail, if you clicked to select a message, this will show a bar on top of the messages table, to perform mass actions on the selected messages (please see the attached GIF photo).

Gif photo

I'm trying to click the delete icon at this bar, but, I can't do that, because, its markup changes once you hover it.

Its first draw at the DOM is like this:

<div class="T-I J-J5-Ji nX T-I-ax7 T-I-Js-Gs mA" act="10" title="Delete" role="button" tabindex="0">
    <div class="asa">
        <div class="ar9 T-I-J3 J-J5-Ji"></div>
    </div>
</div>

And once you manually hover it, it changes to be like this:

<div class="T-I J-J5-Ji nX T-I-ax7 T-I-Js-Gs mA" act="10" role="button" tabindex="0" data-tooltip="Delete" aria-label="Delete" style="user-select: none;">
    <div class="asa">
        <div class="ar9 T-I-J3 J-J5-Ji"></div>
    </div>
</div>

To select it, I use its first markup, like this:

let $delBtn1 = $('[title="Delete"]'); 
let $delBtn2 = $('[data-tooltip="Delete"]');

But, I can't perform the click at it and make it trigger its onclick function, because, I guess it listens to the onclick event AFTER a manual hover at it first.

How can I trigger the manual hover at it then trigger a click?

I tried to do:

$($delBtn1).mouseenter(); 
$($delBtn1).trigger('mouseenter');
$($delBtn1).mouseover(); 
$($delBtn1).trigger('mouseover');
$($delBtn1).mouseup(); 
$($delBtn1).mousedown(); 
$($delBtn1).focus();
$($delBtn1).select();

None of this worked!

Even tried to wait:

$($delBtn1).mouseenter();
setTimeout(function () {
    $($delBtn2).click();
}, 1000);

I'm trying this through a Chrome extension and through the console, and both doesn't work!

Any direction how can I trigger its onclick function?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I did it by using the dispatchEvent() method, like this:

let mouseoverEvent = new MouseEvent('mouseover', {
    view: window,
    bubbles: true,
    cancelable: true
});
let mousedownEvent = new MouseEvent("mousedown", {
    view: window,
    bubbles: true,
    cancelable: true
});
let mouseupEvent = new MouseEvent("mouseup", {
    view: window,
    bubbles: true,
    cancelable: true
});

document.querySelector('div[title="Delete"]').dispatchEvent(mouseoverEvent);
document.querySelector('div[data-tooltip="Delete"]').dispatchEvent(mousedownEvent);
document.querySelector('div[data-tooltip="Delete"]').dispatchEvent(mouseupEvent);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!