mpen
mpen

Reputation: 282865

How to determine if a field has focus?

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

Upvotes: 8

Views: 4314

Answers (2)

Amir Raminfar
Amir Raminfar

Reputation: 34149

You can try

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

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

Upvotes: 10

kojiro
kojiro

Reputation: 77099

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

Upvotes: 3

Related Questions