Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery autocomplete rows highlight on select

I'm using jQuery UI Autocomplete.

When the suggestion box appears and the user presses the Down key (or they move the mouse over one suggestion), I need the entire row to be highlighted. So far, when pressing the Down key, only the background of the hyperlink gets highlighted. I tried styling the ui-state-hover class, but that's only used on the anchor element. I can't figure out how to highlight the li element.

Here's my CSS so far:

.ui-state-hover, .ui-autocomplete li:hover
{
    color:White;
    background:#96B202;
    outline:none;
}

EDIT: To make it a bit more clear, the autocomplete generates its elements like so:

<ul>
<li><a>an element</a></li>
<li><a>another element</a></li>
</ul>

when the down key is pressed, the anchor element automatically gets the class ui-state-hover.

like image 982
Diana Ionita Avatar asked Jun 21 '11 11:06

Diana Ionita


3 Answers

I had exactly the same problem, solved it by:

.ui-state-focus
{
    color:White;
    background:#96B202;
    outline:none;
}
like image 137
Salmon Avatar answered Oct 18 '22 20:10

Salmon


Being a beginner in CSS, I didn't see this earlier: I only had to make the anchor element's style display:block. In case anyone ever runs into this again.

like image 29
Diana Ionita Avatar answered Oct 18 '22 22:10

Diana Ionita


You can use events:

yourElement.autocomplete({
        focus: function(event, ui) { console.log(var li = $(event.srcElement).parent()); },
});

li variable is what you need. You can change style or add class the way you like.

like image 43
Lehych Avatar answered Oct 18 '22 22:10

Lehych