Reteras Remus
Reteras Remus

Reputation: 933

jquery mouseenter - mouseleave not working

I want to change the image in different table td's. I want to change it with javascript, because I'm using a PHP Session variable for 4 different language. That means, I will have 8 different images for one table cell (2 images for 1 language, a normal image and hover image).

I have the following code:

var jsGlobalLang = "<?php echo $_SESSION['lang'];?>";

$(".menu-item").mouseenter(function(){

    var item_id = "";

    switch(this.id)
    {
        case 'home' : { item_id = "acasa";break; }
        case 'proiectaredecasa' : { item_id = "proiectare";break; }
        case 'caseconstruite' : { item_id = "case_construite";break; }
        case 'avantaje' : { item_id = "avantaje";break; }
        case 'oferte' : { item_id = "oferte";break; }
    }

    $(this).html("<img src='images/lang/"+ jsGlobalLang +"_" + item_id + "_hover.gif' alt='' />");
});

It's working, but when I move out the mouse, the function doesn't work. I tried to call an alert(); function to check if the alert box pop's up, but it doesn't.

$(".menu-item").mouseout(function(){
   alert('TEST !');
});

Upvotes: 1

Views: 1805

Answers (3)

Jcodez
Jcodez

Reputation: 11

Which version of jQuery do you use? I use the latest, and it seems there are some problems with mouseout/mouseleave

http://bugs.jquery.com/ticket/12366

Let's wait until they fix this?

Upvotes: 1

locrizak
locrizak

Reputation: 12279

I believe you need to use mouseleave in this situation rather than mouseout

$(".menu-item").mouseleave(function(){
   alert('TEST !');
});

or use mouseover instead of mouseenter.

Upvotes: 1

Nicola Peluchetti
Nicola Peluchetti

Reputation: 76900

Well i think that if you replace the html of the td

 $(this).html("<img src='images/lang/"+ jsGlobalLang +"_" + item_id + "_hover.gif' alt='' />");

There is no mouseout from $(".menu-item") as there is no element with class = .menu-item

I didn't test this but this could be the case

Upvotes: 0

Related Questions