18

I'm trying to reach a parent of some element:

let t = e.target.parentNode

but i have this Error: Property 'parentNode' does not exist on type 'EventTarget'

I've tried with <Element>e.target.parentNode but this also not gives me any results. Can anybody help?

Lukas
  • 7,384
  • 20
  • 72
  • 127
  • Questions seeking debugging help ("**why isn't this code working?**") must include the desired behavior, a *specific problem or error* and *the shortest code necessary* to reproduce it **in the question itself**. Questions without **a clear problem statement** are not useful to other readers. See: [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). – Andreas Aug 02 '17 at 07:49
  • Did you try logging `e.target` on the console? – Rax Weber Aug 02 '17 at 07:49
  • Yes and i have an HTML element – Lukas Aug 02 '17 at 07:49
  • 1
    Maybe you can take a look [here](https://stackoverflow.com/questions/28900077/why-is-event-target-not-element-in-typescript) – Rax Weber Aug 02 '17 at 07:53

1 Answers1

22

I had to wrap the typecasting in parentheses:

let parent = ( <HTMLElement>event.target ).parentElement;

or using parentNode:

let parent = ( <HTMLElement>( <HTMLElement>event.target ).parentNode );
David Stevens
  • 331
  • 1
  • 3