How to select an element that has focus on it with jQuery

jQuery Lover picture jQuery Lover · Feb 5, 2009 · Viewed 88.9k times · Source

How can you select an element that has current focus?

There is no :focus filter in jQuery, that is why we can use something like this:

$('input:focus').someFunction();

Answer

Sam Shiles picture Sam Shiles · Mar 26, 2012

$(document.activeElement) will return the currently focused element and is faster than using the pseudo selector :focus.

Source: http://api.jquery.com/focus-selector/