Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

155
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda