2

Possible Duplicate:
How to select an element that has focus on it with jQuery

I have several HTML elements on the page. I want to write a JQuery code the tells me which element has the focus. I doesn't whether the element gets the focus because I clicked it or I used the tab key. The most important think is that it tells me which element has the focus

$(document).ready(function () {

});

Thank for helping

Community
  • 1
  • 1
Richard77
  • 20,343
  • 46
  • 150
  • 252

2 Answers2

3

document.activeElement should return the current element that is in focus.

Returns the currently focused element, that is, the element that will get keystroke events if the user types any. This attribute is read only.

Ref: https://developer.mozilla.org/en-US/docs/DOM/document.activeElement

Selvakumar Arumugam
  • 79,297
  • 15
  • 120
  • 134
2
var focusedElement = $(':focus');