当前的代码如下:
<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);
});
发布于 2017-08-07 17:28:13
使用prev()来锁定前面的兄弟姐妹
$(".post-meta").each(function() {
$(this).prev("article").append(this);
});发布于 2017-08-07 17:30:59
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>
https://stackoverflow.com/questions/45552514
复制相似问题