JQuery Autocomplete: Get the currently focused <li>

jquery, jquery-autocomplete, jquery-ui, jquery-ui-autocomplete

Solution

You're going to have to:

- Grab the menu widget that autocomplete is using.

Get the `li` that's currently focused (this `li` has an `a` with class `ui-state-focus`

focus: function (event, ui) {
    var menu = $(this).data("uiAutocomplete").menu.element,
    focused = menu.find("li:has(a.ui-state-focus)");
    // focused is the focused `li`
}

Example: http://jsfiddle.net/J5rVP/43/

Problem

JQuery Autocomplete triggers a focus event when the user mouses over or otherwise highlights one of its `<li>` options. Within this event, I want to refer to the `<li>` that is currently focused, but I can't figure out how to select it. At the moment, I have: ``` focus: function( event, ui ) { var target = event.currentTarget alert($(target).html()) } ``` But this returns the whole list of `<li>`s, rather than just the currently focused one. I've tried other event methods, such as event.delegateTarget and event.target, but with no success. Is there another way to get the focused element?

Original source