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

221
Views
Target child element with react

Let's imagine I have this :

<div className='parent'>
  <div className='child'></div>
    <div className='child-1'></div>
  <div className='child'></div>
    <div className='child-1></div>
</div>

And let's imagine you have a dropdown How can I target the child-1 components with the onMouseEnter function by hovering the parent component? I'm new to react, can't find an answer, please

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

0

you can use useRef hook to get the child element

import React, { useRef } from "react";
import "./styles.css";

export default function App() {
  const parentRef = useRef(null);

  const doSomething = () => {
     console.log(parentRef.current.children);
  };


  return (
   <div className='parent' ref={parentRef} onMouseOver={doSomething}>
      <div className='child'></div>
      <div className='child-1'></div>
      <div className='child'></div>
      <div className='child-1></div>
   </div>
  );
}
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!