gpt4 book ai didi

javascript - 如何将每个带有 class 的 ul append 到其上方最接近的文章标签?

转载 作者:行者123 更新时间:2023-12-03 03:42:38 25 4
gpt4 key购买 nike

目前代码如下:

<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/

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