我的页面上有多篇文章,但我想将 h2 标题 move 到(最近的)flexslider div 中,因为我希望标题位于图像上,但我无法让它工作。
HTML:
<article>
<div class="flexslider"></div>
<div class="post-content">
<h2 class="entry-title">Title text</h2>
</div>
</article>
我想要什么:
<article>
<div class="flexslider">
<h2 class="entry-title">Title text</h2>
</div>
<div class="post-content"></div>
</article>
JS 不适合我:
jQuery('article h2.entry-title').appendTo( jQuery('.flexslider') );
最佳答案
您可以使用append( function )
。对于每个.flexslider
,找到.entry-title
同样<article>
并附加它:
$( '.flexslider' ).append( function() {
return $( this ).closest( 'article' ).find( '.entry-title' );
} );
Here's a fiddle
关于jquery - 将元素 move 到最接近的其他具有类的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52854123/