Aye
Aye

Reputation: 281

Alternatives to event.which and event.keyCode in JavaScript

I tried to use the event.which and event.keyCode in my JavaScript code today and got a line ruled across each. I read that both have been deprecated on my VSCode.

Does anyone know the alternatives to them?

Upvotes: 0

Views: 982

Answers (2)

Manish Kumar
Manish Kumar

Reputation: 131

event.keyCode is deprecated , although some browsers do support it. Use event.code instead.

Read this on how to implement crossbrowser for complete support

Upvotes: 1

Yassine Belkaid
Yassine Belkaid

Reputation: 61

To determine what character corresponds with the key event, you need to use event.key instead. The events which/keyCode are indeed deprecated.

Cheers

Upvotes: 1

Related Questions