【发布时间】:2013-01-16 09:31:54
【问题描述】:
我创建了一个函数,当单击 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>
【问题讨论】:
标签: jquery jquery-selectors this