loveforfire33
loveforfire33

Reputation: 1118

Multiple Jquery Functions

Total noob to jquery, i want to add another function on the cotsImg.hover event, to change a second image - just like it changes one below. something like

<script  type='text/javascript'>
$(document).ready(function(){
    $("#cotsImg").hover(
       function() {$('#golfImg').attr("src","/images/golfimagebw.png");}, 
       function() {$('#golfImg').attr("src","/images/golfimage.png");
       function() {$('#golfImg2').attr("src","/images/golfimage2bw.png");}, 
       function() {$('#golfImg2').attr("src","/images/golfimage2.png");

});
});
</script>

Can anyone help? Its been a long day of trying this!

Upvotes: -1

Views: 50

Answers (3)

Suresh Atta
Suresh Atta

Reputation: 122026

You need to pass two functions.

From Jquery Docs of Hover()

The .hover() method, when passed a single function, will execute that handler for both mouseenter and mouseleave events.

So, your one function executing for both the events . You need to remove it after hover done

$("#selectorId").hover(
function() {
   //Do something to element here
},

 function() {
    //make your element normal here
   }

);

Or classic style.

 $("#cotsImg")
        .mouseover(function() { 

            $(this).attr("src", "/images/golfimagebw.png");
        })
        .mouseout(function() {
             $(this).attr("src", "/images/golfimage.png");
        });

Upvotes: 2

Sualkcin
Sualkcin

Reputation: 526

If I understand your question, then you don't need more functions, just execute those lines of code excluding the functions.

Upvotes: 0

Tushar Gupta
Tushar Gupta

Reputation: 15933

<script  type='text/javascript'>
$(document).ready(function(){
    $("#cotsImg").hover(function(){
       $('#golfImg').attr("src","/images/golfimagebw.png"); 
       $('#golfImg').attr("src","/images/golfimage.png");
       $('#golfImg2').attr("src","/images/golfimage2bw.png"); 
       $('#golfImg2').attr("src","/images/golfimage2.png");

});
});
</script>

just like that add what you want :)

Upvotes: 0

Related Questions