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

220
Visualizações
Propagation MouseEvent And Target Style Query

I have 2 containers, one on top of the other, being controlled by zIndex whether event is mouseover/mouseout;

There is an issue with event bubbling whereby the child element fires off the parent event. I could change the event to mouseleave from mouseout which resolves the issue but how would I go about then changing the zIndex of the target element?

giphyContainer.addEventListener('mouseover', (e) => {

    let backPanel = e.target.parentElement.querySelector('.giphyImg__Back');
    let frontPanel = e.target.parentElement.querySelector('.giphyImg__Front');
    let target = e.target;
    
    if (target.className === "giphyImg__Front") {
        frontPanel.style.zIndex = "-3";
        backPanel.style.zIndex = "3";
    }
});

giphyContainer.addEventListener('mouseleave', (e) => {

    // Previously worked with event of mouseout
    // let backPanel = e.target.parentElement.querySelector('.giphyImg__Back');
    // let frontPanel = e.target.parentElement.querySelector('.giphyImg__Front');

    // console.log(backPanel);
    // e.target - event that troggered the event
    // e.currentTarget - the event listener element

    console.log(e);
    let backPanel2 = e.target.firstChild.lastElementChild;
    let frontPanel2 = e.target.firstChild.firstElementChild;
    console.log(backPanel2);
    console.log(frontPanel2);

    if (backPanel2.className === "giphyImg__Back") {
        frontPanel2.style.zIndex = 3;
        backPanel2.style.zIndex = -3;
    }
});
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can stop the event from bubbling on to the parent by using event.stopPropagation() on your child elements.

child.addEventListener('mouseout',(event) => {
  event.stopPropagation();
})
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