How can I enhance a MouseOver on image script? [closed]
I have written a small script. Here is the demo : http://jsfiddle.net/kolxoznik1/MfLuU/3/
Everything works good, but I need to optimize it because in my opinion code isn't written as it should be. Like to hear what can be improved.
Your HTML is invalid - that's why jsfiddle highlighted your last div
tag. Make sure you close your img
tag and the closing anchor tag had the slash in the wrong place.
<a href="#"><img src="http://i.cdn.turner.com/cnn/2011/WORLD/europe/09/04/france.strauss.kahn.arrival/c1main.strauss.kahn.paris.jpg" alt="" title="" class="medium_photo right"/></a>
You can use chaining on your jQuery calls. You should probably also use find
so you only get the .b
that is underneath the current .a
$(".a").mouseover(function() {
$(this).find('.b').show();
}).mouseout(function() {
$(this).find('.b').hide();
});
Take a look at jQuery's toggle() method.
精彩评论