Why is Event target not Element in Typescript

0 votes

I simply want to do this with my KeyboardEvent

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

While Event.target is of type EventTarget, it does not inherit from Element. So I have to cast it like this:

var tag = (<Element>evt.target).tagName.toLowerCase();

This is probably due to some browsers not following standards, right? What is the correct browser-agnostic implementation in TypeScript?

P.S. I am using jQuery to capture the KeyboardEvent.

Aug 3 in TypeSript by Elton
• 400 points
23 views

1 answer to this question.

0 votes

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

if (event.target instanceof Element) { /*...*/ }
answered Aug 3 by Abhinaya
• 760 points

Related Questions In TypeSript

0 votes
1 answer

What is TypeScript and why would I use it in place of JavaScript?

TypeScript is a superset of JavaScript which primarily ...READ MORE

answered May 31 in TypeSript by Nina
• 3,020 points
13 views
0 votes
1 answer

What is "not assignable to parameter of type never" error in TypeScript?

All you have to do is define ...READ MORE

answered May 31 in TypeSript by Nina
• 3,020 points
839 views
0 votes
1 answer
0 votes
1 answer

Wildcard module declaration not work in TypeScript 2, why?

I managed to resolve this by forcing ...READ MORE

answered Jun 16 in TypeSript by Nina
• 3,020 points
65 views
0 votes
1 answer

Cannot access web3 object with typescript and ethereum

You still need to instantiate it first. ...READ MORE

answered Sep 25, 2018 in Blockchain by slayer
• 29,310 points
1,861 views
0 votes
1 answer

How to apply zoom animation for each element of a list in angular?

Hey @Sid, do check if this link ...READ MORE

answered Jul 30, 2019 in Others by Vardhan
• 13,200 points
511 views
0 votes
1 answer

Can't bind to 'formGroup' since it isn't a known property of 'form'

In order to rectify this error, you ...READ MORE

answered Feb 10 in Others by Rahul
• 9,000 points
1,257 views
0 votes
1 answer

What is the question mark for in a Typescript parameter name?

It is to mark the parameter as optional. TypeScript ...READ MORE

answered Aug 3 in TypeSript by Abhinaya
• 760 points
17 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP