Skip to content Skip to sidebar Skip to footer

How Can Use "getModifierState" On Focus Event With JS?

I'm trying to get caps lock status on focus event of input this is my code $('#Input')[0].addEventListener('focus', function (key) { if (key.originalEvent.

Solution 1:

There are different types of event object. getModifierState is only defined for KeyboardEvent (such as a keydown) and MouseEvent (such as a click); focus is neither.

You might look at using click and remembering whether you already had focus (e.g., so you don't repeat the action if the click is in an already-focussed element). Ugh, no, that's a terrible suggestion. There are lots of ways your element might get focus other than clicks.


Post a Comment for "How Can Use "getModifierState" On Focus Event With JS?"