How to determine if the field is focused?

Very similar to How do I know which DOM element has focus? except that I'm not trying to find a field with focus, I just need to know if someone already has focus. Is it possible?

+8
javascript jquery
source share
2 answers

You can try

$("input#id").is(":focus") 

Edit : You should read this post if you plan to use it in older browsers. http://forum.jquery.com/topic/is-the-focus-selector-valid

+11
source share

You can do this quite simply with jQuery: $(el).is(":focus")

+3
source share

All Articles