gpt4 book ai didi

jquery - 将元素 move 到最接近的其他具有类的元素

转载 作者:行者123 更新时间:2023-12-01 07:39:39 25 4
gpt4 key购买 nike

我的页面上有多篇文章,但我想将 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/

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