In a small application I check if the cursor is over this object. In chrome and firefox, a test like if($(this).is(":hover")) works normally, but in safari this code always returns false .

Can anyone tell me how to solve this nuance?

  • one
    I think in the case of Safari should indicate the version of the browser. For up-to-date Mac Safaris and Ancient Safaris for Windows are two big differences - lexxl
  • I would also like to know, but unfortunately I do not own the information. there is a suspicion that some makoyuzerov can stand and the old version of the safari - xtfkpi

1 answer 1

There is an alternative in the form of mouseover and mouseleave events that work fine in Safari (5.1.7 for Windows). Here is an example:

 $('.test').on('mouseenter', function() { $(this).css('background-color', '#eee'); }).on('mouseleave', function() { $(this).removeAttr('style'); }); 
 .test { border: 1px solid #000; width: 100px; height: 100px; margin: 25px; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div class='test'></div> 

JS Bin example

Still read the article: " Mouse: move mouseover / out, mouseenter / leave ".
It will help to better understand these events.

  • 3
    "but jquery cross browser" Apparently you need to write a bug report to them on this topic - Vasily Barbashev
  • Thanks for the tip. I did not think that you can write a bugreport. In theory, this is exactly the Jickvery task of ensuring cross - browser compatibility - xtfkpi