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!
-
Could you show us the HTML?Alex Funk– Alex Funk2013年08月27日 20:41:50 +00:00Commented Aug 27, 2013 at 20:41
-
You want to replace with new image on each hover? Explain better pleaseSergio– Sergio2013年08月27日 20:42:12 +00:00Commented Aug 27, 2013 at 20:42
-
You should have 2 functions the first one for mouseenter the second one for mouseleaveiConnor– iConnor2013年08月27日 20:58:51 +00:00Commented Aug 27, 2013 at 20:58
3 Answers 3
You need to pass two functions.
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");
});
Comments
<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 :)
1 Comment
If I understand your question, then you don't need more functions, just execute those lines of code excluding the functions.