tags:

views:

54

answers:

2

Hi, i can't understand why just the first function ($("#ContentWel")) works.

But if I put the second function ("#ContentCan") in the first place it only works:

$(document).ready(function(){

    $("#ContentWel").hover(function(){
    $('#counterimage').attr('src', 'img/01.png');
    });

    $("#ContentCan").hover(function(){
    $('#counterimage').attr('src', 'img/02.png');
    });

    $("#ContentCli").hover(function(){
    $('#counterimage').attr('src', 'img/03.png');
    });

    $("#ContentTesti").hover(function(){
    $('#counterimage').attr('src', 'img/04.png');
    });

    $("#ContentCont").hover(function(){
    $('#counterimage').attr('src', 'img/05.png');
    });

    $("#ContentPri").hover(function(){
    $('#counterimage').attr('src', 'img/06.png');
    });

});

Thanks, Guilherme

+3  A: 

.hover() need a mouseenter and mouseleave function

$("#ContentWel").hover(function(){
    $('#counterimage').attr('src', 'img/01.png');
 }, function(){
    // something else happens
});

or you just use mouseenter:

$("#ContentWel").mouseenter(function(){
    $('#counterimage').attr('src', 'img/01.png');
});
meo
The first option works! Thanks a lot.The second don't worrk.
Mango
A: 

To gain more visibility into your functions add try/catches

try {
 $("#ContentWel").hover(function(){
    $('#counterimage').attr('src', 'img/01.png');
    });
 } catch (e) { if (window.console !== undefined && window.console.log !== undefined) { window.console.log(e.message); } else { alert(e.message); } }
 try {
    $("#ContentCan").hover(function(){
    $('#counterimage').attr('src', 'img/02.png');
    });
 } catch (e) { if (window.console !== undefined && window.console.log !== undefined) { window.console.log(e.message); } else { alert(e.message); } }
 try {
    $("#ContentCli").hover(function(){
    $('#counterimage').attr('src', 'img/03.png');
    });
 } catch (e) { if (window.console !== undefined && window.console.log !== undefined) { window.console.log(e.message); } else { alert(e.message); } }
 try {
    $("#ContentTesti").hover(function(){
    $('#counterimage').attr('src', 'img/04.png');
    });
 } catch (e) { if (window.console !== undefined && window.console.log !== undefined) { window.console.log(e.message); } else { alert(e.message); } }
 try {
    $("#ContentCont").hover(function(){
    $('#counterimage').attr('src', 'img/05.png');
    });
 } catch (e) { if (window.console !== undefined && window.console.log !== undefined) { window.console.log(e.message); } else { alert(e.message); } }
 try {
    $("#ContentPri").hover(function(){
    $('#counterimage').attr('src', 'img/06.png');
    });
 } catch (e) { if (window.console !== undefined && window.console.log !== undefined) { window.console.log(e.message); } else { alert(e.message); } }
mike clagg
his question is not how to debug. :)
meo
Yes it was. Without any debugging code in there, he was screaming for debug code ;)
mike clagg
ok i then, just use jquery.lint :P
meo