Javascript/jQuery detect if input is focused [duplicate]

With pure javascript:

this === document.activeElement // where 'this' is a dom object

or with jquery's :focus pseudo selector.

$(this).is(':focus');

If you can use JQuery, then using the JQuery :focus selector will do the needful

$(this).is(':focus');