【发布时间】:2011-04-05 20:51:41
【问题描述】:
多个div与jQuery同一个类的情况下如何使用Toggle?我只想在点击时显示一个 div。
JavaScript
$(".help_content").hide();
$(".help_target").click(function()
{
$('.help_content').toggle(); // I also tried with $(".help_content").show();
});
HTML
<div id="foo">
<p class="help_target">
<a href="#">Click</a>
</p>
</div>
<p class="help_content">Asia</p>
<div id="some">
<p class="help_target">
<a href="#">Click</a>
</p>
</div>
<p class="help_content">Africa</p>
我不能使用 next(),因为 .help_content 不是 .help_target 的后代。 (我想在字段集中使用 .help_target 并在字段集中显示 .help_content)。
【问题讨论】: