Search code examples
javascriptjquerymouseovermouseout

Mouseover and Mouseout issue


So I'm having a problem because I would like to remove the mouse from the DIV background turns red, this is working, but when I move the mouse on the title that is inside the div, it already happens this mouse event out! What am I suposed to do ??

Here is the code: http://jsfiddle.net/eluminium/t5YEC/1/

var $imoveis = $('.imoveis');
$imoveis.mouseover(function() {
    var index = $(this).index();
});

$imoveis.mouseout(function() {
    var index = $(this).index();
    $imoveis.eq(index).css({
        background: 'red'
    });
})​;​

Solution

  • Try binding the mouseleave event

    function imoveis(){
        var $imoveis = $('.imoveis');
    
        $imoveis.mouseover(function(){
            var index = $(this).index();
        });
    
        $imoveis.mouseleave(function(){
            var index = $(this).index();
    
            $imoveis.eq(index).css({
                background: 'red'
            });
         });
    }
    

    Demo

    Documentation