开发者

How can I enhance a MouseOver on image script? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rh开发者_开发知识库etorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜