I have a span element that I want to give focus to after popping up a dialog box when the span is clicked. The span contains two glyphs, only one of which is displayed at any given moment. When the item is not checked in yet, the unchecked
icon is displayed, and after the item is checked in, the checked
icon is displayed.
<span ng-click="checkIn(this, item)">
<span class="glyphicon glyphicon-unchecked" style="display:inline"></span>
<span class="glyphicon glyphicon-checked" style="display:none"></span>
<span>
Some of the details have been omitted for brevity.
The checkIn()
function does all the work of checking in or checking out the item, displaying a dialog box, etc. I'd like to pass it the span element that was clicked, so that after all the check-in/check-out work is done, I can give focus back to it.
I've tried this:
function checkIn(elem, item)
{
elem = angular.element(elem);
...code to display pop-ups and check item in/out...
elem.focus();
}
Even though elem
is indeed a non-null object, calling elem.focus()
does not do appear to do anything; after the dialog div is closed (hidden), the focus returns to the top element in the browser window.
I've also tried passing the $event
object and using $event.target
, but with the same results.
I've also tried passing the ID of the span and accessing it with document.getElementById()
, but still the same results.
What am I doing wrong?