我创建了一个函数,在li
单击元素时淡入一些描述性信息。该函数淡化列表中的新信息。不工作的线路是$(".hover").not(".hover", this).fadeOut(200).removeClass("not-me");
并且理解它是下降到.not(".hover", this)
.
我已经尝试过.not(this)
,但这不能正常工作。大概是因为this
它的部分还是从li
元素中选取的,最初是从点击函数中选取的$("ul li").click(function() {
。
有没有办法.not(".hover", this)
成功使用?
jQuery:
$("ul li").click(function() {
// Remove other divs with element currently shown
$(".hover").not(".hover", this).fadeOut(200).removeClass("not-me");
// Stop chosen element from fading out
$(".hover", this).addClass("not-me").fadeIn(200);
});
HTML:
<li>
<div class="hover">
<h3>Header</h3>
<p>Shot but breif description, cut me off if you need to.</p>
</div>
<img src="/images/1.jpg" alt="" />
</li>
<li>
<div class="hover">
<h3>Header</h3>
<p>Shot but breif description, cut me off if you need to.</p>
</div>
<img src="/images/2.jpg" alt="" />
</li>
<li>
<div class="hover">
<h3>Header</h3>
<p>Shot but breif description, cut me off if you need to.</p>
</div>
<img src="/images/3.jpg" alt="" />
</li>