Javascript: Finding the Focused Element

Lately I've run into a brick wall. While working on the new version of Impromptu, I've had many requests to restrict the tab out of the prompt. Problem is how do you determine which element has focus without some ugly hacks like adding a class name to the element on its focus event, then removing it on blur.

The ideal solution would have jquery selector for :focus which would return the focused element, so then I would do something like so:

if($('.jqi :focus').length == 0){ $('.jqi').focus(); }

The problem is this selector isn't implemented, or is it(are there any plugins out there)? Is it possible to retrieve such? Well of course everything is possible, but may not be pretty! So, does anyone have any suggestions?