How to control jquery show hide for each one?
How to control jquery show hide for each one? I want mouseover 111, show Hello 1. mouseover 222, show Hello 2. mouseover 333, show Hello 3. Thanks.
<head>
<style>
.menu{ display:none; }
</style>
<script src="http://code.jquery.com/jquery-1.5.js"></script>
</head>
<body>
<ul>
<li>
<a href="" class="link">111</a>
<div class="menu">Hello 1</div>
</li>
<li>
<a href="" class="link">222</a>
<div class="menu">Hello 2</div>
</li>
开发者_开发百科<li>
<a href="" class="link">333</a>
<div class="menu">Hello 3</div>
</li>
</ul>
<script>
$(document).ready(
function(){
$(".link").mouseover(function(){
$(".menu").show(".slow");
});
$(".menu").mouseout(function () {
$(".menu").hide("slow");
});
});
</script>
</body>
Try using hover as given below:
$(document).ready(
function(){
$(".link").hover(function(){
$(this).next().show("slow");
},function () {
$(this).next().hide("slow");
});
});
Working example @:
http://jsfiddle.net/6hTZR/3/
$(".link").mouseover(function () {
$(this).closest('li').find('.menu').show('slow');
});
$(".menu").mouseout(function () {
$(this).hide("slow");
});
Use this $(".menu", this)
instead of $(".menu")
.
Try this:
$(".link").hover(
function(){
$(this).next("div.menu").fadeIn("fast");
},
function(){
$(this).next("div.menu").fadeOut("fast");
}
);
精彩评论