8

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?

Community
  • 1
  • 1
mpen
  • 272,448
  • 266
  • 850
  • 1,236
  • 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 Answers2

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
  • 1
    Try is correct since it doesn't work everywhere I believe, so this is best answer, or $("*:focus") – macarthy Mar 01 '11 at 01:06
3

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

kojiro
  • 74,557
  • 19
  • 143
  • 201