I’d like to find the currently focused element in the whole document.
I tried using the :focus pseudoclass introduced with jQuery 1.6:
$(document).find(":focus")
But $(document).find(":focus").length always returns 0
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You should be able to use the
activeElementproperty of thedocument:If you look at the jQuery documentation for
:focusit makes this perfectly clear:It’s worth noting that if no element currently has focus,
activeElementwill refer to thebody.