`var $focused = $(':focus');` would be a better way of getting the currently focussed element.