Angular property 'parentNode' does not exist on type 'EventTarget'

Lukas picture Lukas · Aug 2, 2017 · Viewed 8.1k times · Source

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?

Answer

David Stevens picture David Stevens · Aug 24, 2017

I had to wrap the typecasting in parentheses:

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

or using parentNode:

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