I’m using jQuery 1.12. I have this class for when someone hovers over an LI element
.select-options li:hover {
color: gray;
background: #fff;
}
How do I use jQuery to trigger applying this class to an LI element? I have tried this
$(".select").bind('keydown', function(event) {
elt = $(this).find('.select-options li:hover')
if (elt.length == 0) {
elt = $(this).find('.select-options li:first')
} // if
var next;
switch(event.keyCode){
// case up
case 38:
break;
case 40:
next = $(elt).next();
console.log($(next).text());
$(next).trigger('mouseenter');
break;
}
});
but the $(next).trigger('mouseenter'); doesn’t seem to be working. You can check out my Fiddle here — http://jsfiddle.net/cwzjL2uw/15/ . Click the “select State” drop down and then click the down key on your keyboard to trigger the block of code above.