0

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

1
  • What's the html page you are using ? Commented May 10, 2010 at 17:07

2 Answers 2

4

.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');
});
Sign up to request clarification or add additional context in comments.

1 Comment

The first option works! Thanks a lot. The second don't worrk.
0

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); } }

2 Comments

his question is not how to debug. :)
Yes it was. Without any debugging code in there, he was screaming for debug code ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.