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?
Asked
Active
Viewed 4,287 times
8
-
Um, can't you use the solutions in that question to find the focused element and compare it against the element of your chosing? – ide Mar 01 '11 at 01:04
-
@ide: yes. was just leaving work, didn't have time to read through all the solutions. – mpen Mar 01 '11 at 01:41
2 Answers
10
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

Amir Raminfar
- 33,777
- 7
- 93
- 123
-
1Try is correct since it doesn't work everywhere I believe, so this is best answer, or $("*:focus") – macarthy Mar 01 '11 at 01:06