How can I check if a keyboard or mouse event is done inside of a div?
Once I check the onmousemove() event of a div it works but onkeyup, onkeypress etc are not working for the div.
What is the reason for that?
<div onmousemove="alert(1);" onkeypress="alert(2);">
Here alert(1) will be displayed but alert(2) is not displayed.
The div must have focus.
Here is how you do it:
1- Tabindex:
Or
2- setting contentEditable to true:
Or
Links:
How do I give an HTML canvas the keyboard focus using jquery?
How do you set focus to the HTML5 canvas element?