gpt4 book ai didi

javascript - 切换具有相同名称的 div 标签

转载 作者:行者123 更新时间:2023-11-30 10:02:24 29 4
gpt4 key购买 nike

有没有办法切换 div 标签和它下面的 div(直到它到达同名的 div 标签)?

<div class="div">Here is more to read.</div>
<div class="job_description">Here is more to read.</div>
<div class="job_description">Here is more to read.</div>
<div class="job_description">Here is more to read.</div>

<div class="div">Here is more to read.</div>
<div class="job_description">Here is more to read.</div>
<div class="job_description">Here is more to read.</div>
<div class="job_description">Here is more to read.</div>

<div class="div">Here is more to read.</div>
<div class="job_description">Here is more to read.</div>
<div class="job_description">Here is more to read.</div>

我的 jQuery 似乎不起作用

 jQuery(function() {
jQuery('.div').click(function() {
var nextArticle = jQuery(this).siblings('.job_description.'+jQuery(this))

if (nextArticle.length) {
nextArticle.is(':visible') ? nextArticle.slideUp() : nextArticle.slideDown();
}

return false;
});
});

谢谢

最佳答案

您可以使用 jQuery 的 nextUntil() slideToggle() 一行完成:

jQuery('.div').click(function() {
$(this).nextUntil(':not(.job_description)').slideToggle();
});

查看演示:http://jsfiddle.net/tgr3nyx4/2/

关于javascript - 切换具有相同名称的 div 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30907057/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com