mardi 23 juin 2020

How to add mouseover event for an option element inside a select tag?

How to add mouseover event for an option element inside a select tag?

It is working for select with mutiple option selection but not supported for select with single option selection. Is there a reason for this behavior?

Below is the sample to reproduce: sample to see in action

    <!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
<div>

<select id="pet-select" multiple>
    <option value="">--Please choose an option--</option>
    <option onmouseover="console.log('hello1')" value="dog">Dog</option>
    <option onmouseover="console.log('hello1')" value="cat">Cat</option>
</select>
  </div>
    <div style="margin-top:30px">
  <select id="pet-select">
    <option value="">--Please choose an option--</option>
    <option onmouseover="console.log('hello2')" value="dog">Dog</option>
    <option onmouseover="console.log('hello2')" value="cat">Cat</option>
</select>
    </div>

</body>
</html>



Aucun commentaire:

Enregistrer un commentaire