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

212
Views
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 answers
Answer question

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 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!