Home > Article > Web Front-end > How to Display Select Box Options on Hover Instead of Clicking?
Hovering to Display Select Box Options
The issue presented involves creating a select box that displays options on hover instead of after clicking. The code provided is a simple select box:
<select name="size"> <option value="small">Small</option> <option value="medium">Medium</option> <option value="large">Large</option> </select>
Solution
The provided jQuery solution aims to achieve the desired behavior:
$('#selectUl li:not(":first")').addClass('unselected'); $('#selectUl').hover( function(){ $(this).find('li').click( function(){ $('.unselected').removeClass('unselected'); $(this).siblings('li').addClass('unselected'); var index = $(this).index(); $('select option:selected').removeAttr('selected'); $('select[name=size]') .find('option:eq(' + index + ')') .attr('selected',true); }); }, function(){ });
Explanation
Additional Features
The solution has been extended to include:
The above is the detailed content of How to Display Select Box Options on Hover Instead of Clicking?. For more information, please follow other related articles on the PHP Chinese website!