目前代码如下:
<article id="post-529"></article>
<ul class="post-meta"></ul>
<article id="post-530"></article>
<ul class="post-meta"></ul>
<article id="post-531"></article>
<ul class="post-meta"></ul>
我需要将每个带有 post-meta 类的 ul append 到它们正上方的文章中。你们有什么线索吗?我使用了以下函数,但它只是将所有 ul append 到所有文章中。我真的很感激任何帮助。非常感谢。
$(".post-meta").each(function() {
$(this).siblings("article").append(this);
});
最佳答案
使用prev()
以前一个兄弟为目标
$(".post-meta").each(function() {
$(this).prev("article").append(this);
});
关于javascript - 如何将每个带有 class 的 ul append 到其上方最接近的文章标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45552514/