HTML
<div class="page-content">
<div class="something">
<img class="image" src="something alt="something">
</div>
<div class="another-div-in-there"></div>
<div class="gallery">
//stuff in there
</div>
<div class="something">
<img class="image" src="something alt="something">
</div>
<div class="another-div-in-there"></div>
<div class="another-div-in-there"></div>
<div class="gallery">
//stuff in there
</div>
<div class="something">
<img class="image" src="something alt="something">
</div>
<div class="another-div-in-there"></div>
<div class="gallery">
//stuff in there
</div>
</div>
<小时/>
jQuery
$(".page-content .image").each(function(i) {
//$(this).closest('.gallery') ??
});
如何为每个`.image``找到/选择“下一个”或“后续”.gallery
因此,当运行 each()
循环时,我想要第一个图像的第一个画廊。
当运行第二个.image
时,我想找到dom树中第二个.image
“下方”的.gallery
。
知道该怎么做吗?
最佳答案
这个插件就是为此而编写的。 免责声明:我写的
http://techfoobar.com/jquery-next-in-dom/
$(".page-content .image").each(function() {
$(this).nextInDOM('.gallery');
});
关于javascript - jQuery:总是在 dom 树中的图像下方找到下一个 .gallery?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14425598/