Why is Event.target not Element in Typescript?

后端 未结 8 828
情歌与酒
情歌与酒 2020-12-01 03:55

I simply want to do this with my KeyboardEvent

var tag = evt.target.tagName.toLowerCase();

While Event.target is of type EventTarget it doe

8条回答
  •  失恋的感觉
    2020-12-01 04:28

    JLRishe's answer is correct, so I simply use this in my event handler:

    if (event.target instanceof Element) { /*...*/ }
    

提交回复
热议问题