I am developing an application (game) which could be controlled using keyboard. The problem is that it also contains some default input elements (like login form fields). In order to prevent game reacting to keypresses when user enters their credentials, I do such a check:
if (isDef($("*:focus").attr("id")))
return;
It works just great in almost all major browsers, but IE. In the Internet Explorer div's could also have focus on them and in almost every case some element on the page has focus on it. Thus, I want to check not if some element has focus, but some element, which can accept keyboard input has focus. In my case it's limited to textarea or input. How do I check if elements of those two types have focus?
if (isDef($("input:focus,textarea:focus").attr("id")))
?