Search code examples
javascriptjqueryhoveroperajquery-events

Alternative to .is(":hover")? Doesn't work in Opera


See http://jsfiddle.net/cgWdF/3/

Works fine in every browser*, except the latest Opera.

*Haven't tested below IE9

Should have specified, It needs to return true or false, I'm not using it to bind an event.


Solution

  • jQuery's .hover works in Opera 12.

    var $sample = $("#sample");
    $sample.hover(function() {
       $sample.css("background", "yellow");
    }, function() {
        $sample.css("background", "");
    });
    

    Fiddle

    Or, using .data to store the hovered status and test against it (similar to your original fiddle):

    var $sample = $("#sample");
    $sample.hover(function() {
       $(this).data('hovering', true);
    }, function() {
       $(this).data('hovering', false);
    });
    
    setInterval(function(){
        var $sample = $("#sample");
        if($sample.data('hovering')) {
           $sample.css("background", "yellow");
        }
        else {
           $sample.css("background", "");
        }
    }, 200);
    

    Fiddle