如何将每个单独的ul添加到上面最近的文章标签中?
问题描述:
目前的代码如下:如何将每个单独的ul添加到上面最近的文章标签中?
<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>
我需要与后级的元追加的文章右上方他们每一个人UL认证。你们有什么线索吗?我使用了下面的函数,但它只是将所有的ul添加到所有文章中。我非常感谢任何帮助。非常感谢。
$(".post-meta").each(function() {
$(this).siblings("article").append(this);
});
答
的DOM previousElementSibling
属性会得到你所需要的。
$(".post-meta").each(function() {
this.previousElementSibling.append(this);;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<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>
是的!那工作。非常感谢! – user3821656