0

In React 18.2 with TypeScript I have:

export default function App() {
  const clikHandler = (event: React.MouseEvent<HTMLElement>) => {
    console.log(event.target.id); // Property 'id' does not exist on type 'EventTarget'.
  };

  return (
    <div className="App">
      <div id="parent" onClick={clikHandler}>
        <div id="child"></div>
      </div>
    </div>
  );
}

But id does exist. Even if I use HTMLDivElement it still complains.

The event is in a parent DIV element and I want to get the ID of the child element that was clicked.

user5507535
  • 1,580
  • 1
  • 18
  • 39

0 Answers0