Skip to content Skip to sidebar Skip to footer

Select Element Onmouseleave Event In Safari

I want to catch the mouse leaving a select box with the code below. In Chrome this works great, but in Safari the event fires also when moving from the box to the options inside. H

Solution 1:

seems like onmouseleave is not well supported in safari so I ended up using onmouseout instead:

var s=document.getElementById("myselect");
s.onmouseout = (e => {
  let related=(e.relatedTarget ? e.relatedTarget.tagName : null);
  if (related!=='SELECT' && related!=='OPTION') alert("left select box");
});
<select id="myselect" size=4>
  <option>first</option>
  <option>second</option>
  <option>third</option>
  <option>forth</option>
 </select>

Post a Comment for "Select Element Onmouseleave Event In Safari"