jQuery – Mouseover Select Options

  Kiến thức lập trình

I have searched for this and so far have not found a solution, unless it’s to use a plug in or change the select dropdown to a list and style it.

Is it possible to capture the value of a select option as you hover over it ?

I have the following dropdown:

<select id="testSelect">
    <option value="0">Disable</option>
    <option value="1">Enable</option>
    <option value="2">Hidden</option>
    <option value="4">Failover</option>
</select>

I’ve tried using the following but nothing is shown in the console log.

$('#testSelect :option').mouseover(function(e) {
    console.log ( $(this).val() )
})

Is this possible, and if it is how do I get the value of the option as I hover over it ?
I need this to be supported in Edge, Chrome, Firefox and Safari.

Thanks

LEAVE A COMMENT