jQuery 选择器问题:单击一个元素将修改紧邻的下一个元素
jQuery selector problem: clicking one element will modify the immediate next element
我想使用 jquery 在单击标题 类 时向下滑动描述 类。然而,我想要做的是当点击一个特定的标题时,只有紧接着的下一个描述应该向下滑动。我怎样才能在一个代码块中做到这一点?
$(document).ready(function(){
$(".title").click(function(){
$(".description").slideToggle();
})
})
<div> <h2 class="title">title</h2>
<table class="description">description</table>
</div>
<div> <h2 class="title">title</h2>
<table class="description">description</table>
</div>
<div> <h2 class="title">title</h2>
<table class="description">description</table>
</div>
<div> <h2 class="title">title</h2>
<table class="description">description</table>
</div>
$(".description").slideToggle();
获取带有 class=description
的所有元素,而不仅仅是您想要的元素。
在所选标题附近使用 next()
。
$(document).ready(function(){
$(".title").click(function(){
$(this).next(".description").slideToggle();
})
})
我想使用 jquery 在单击标题 类 时向下滑动描述 类。然而,我想要做的是当点击一个特定的标题时,只有紧接着的下一个描述应该向下滑动。我怎样才能在一个代码块中做到这一点?
$(document).ready(function(){
$(".title").click(function(){
$(".description").slideToggle();
})
})
<div> <h2 class="title">title</h2>
<table class="description">description</table>
</div>
<div> <h2 class="title">title</h2>
<table class="description">description</table>
</div>
<div> <h2 class="title">title</h2>
<table class="description">description</table>
</div>
<div> <h2 class="title">title</h2>
<table class="description">description</table>
</div>
$(".description").slideToggle();
获取带有 class=description
的所有元素,而不仅仅是您想要的元素。
在所选标题附近使用 next()
。
$(document).ready(function(){
$(".title").click(function(){
$(this).next(".description").slideToggle();
})
})