只影响jquery中带有相同类的多个元素的clicked元素 [英] affect only the clicked element in jquery for multiple elements with same class
本文介绍了只影响jquery中带有相同类的多个元素的clicked元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在寻找所有的解决方案,但我只是不能弄清楚如何。
i've been looking all over for a solution to this but i just can't figure out how.
我想要的是特定的标题是
what i want is for the specific header that was clicked to be the only one to expand.
演示在这里: http://jsfiddle.net/bm92L0eg/1/
html:
<h3 class="click-list">header a</h3>
<ul class="open-list">
<li>item</li>
<li>item</li>
<li>item</li>
</ul>
<h3 class="click-list">header b</h3>
<ul class="open-list">
<li>item</li>
<li>item</li>
<li>item</li>
</ul>
<h3 class="click-list">header c</h3>
<ul class="open-list">
<li>item</li>
<li>item</li>
<li>item</li>
</ul>
jquery:
$('.click-list').click(function() {
$(this).find('.open-list').slideToggle(600);
});
jQuery代码不工作,而下面的代码是激活所有头文件:
that jquery code didn't work while this code below is the one that acivates all headers:
$('.open-list').slideToggle(600);
推荐答案
使用 .next
选择相邻的 .open-list
元素。
/ p>
It should be:
$('.click-list').click(function () {
$(this).next('.open-list').slideToggle(600);
});
这篇关于只影响jquery中带有相同类的多个元素的clicked元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文