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

141
Views
How to catch mouse event over multiple divs

I have many components that are on top of each other, and I need to add a listener so when a mouse pointer is in bounds of these components every component will do something.

I tried with mouseover, mouseenter, mousemove, etc. but these events works only on the component that is on top, not on all of them. ex html:

<div class="container">
    <app-child></app-child>
    <app-child></app-child>
    <app-child></app-child>
    <app-child></app-child>
</div>

ex css:

.container > * {
    position: absolute;
    left: 0;
    top: 0;
    width: 100px;
    height: 100px;
    border: 1px solid black;
}

ex app-child.component.ts

@Component({
    selector: 'app-child',
    template: '<div></div>'
})
ChildComponent {
    
    // Here some function that needs to run if mouse pointer is in bound of this element

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

0

if you want the children to do something

parent.component.html

<div class="container" (mouseenter)="doSomethingFunction()" (mouseleave)="stopDoSomething()>
    <app-child [doSomething]="doSomething"></app-child>
    <app-child [doSomething]="doSomething"></app-child>
    <app-child [doSomething]="doSomething"></app-child>
    <app-child [doSomething]="doSomething"></app-child>
</div>

parent.component.ts

@Component({
    selector: 'app-child',
    template: '<div></div>'
})
ParentComponent {

   
    doSomething = false;
    doSomethingFunction(e) {
        doSomething = true;
    }

    stopDoSomething(e) {
        doSomething = false;      
    }

}

child.component.ts

@Component({
    selector: 'app-child',
    template: '<div></div>'
})
ChildComponent {
    @Input() doSomething: boolean

    
    ngOnInit() {
         if(doSomething) {
             doSomethingElse();
         } else {
             stopDoingThings();
         }
    }

}

if you have to do something to the children

parent.component.html

<div class="container" (mouseenter)="doSomething($event)">
    <app-child></app-child>
    <app-child></app-child>
    <app-child></app-child>
    <app-child></app-child>
</div>

parent.component.ts

@Component({
    selector: 'app-child',
    template: '<div></div>'
})
ParentComponent {

    
    doSomething(e) {
        for(const child in Array.from(e.target.children) {
            doSomethingElse(child);
        }
    }

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