0

a href 要素を p 要素の最後に移動しようとしています。

<div class="press-text">
    <h2></h2>
    <h3></h3>
    <p></p>
    <a class="press-file"></a>
</div>
<div class="press-text">
    <h2></h2>
    <h3></h3>
    <p></p>
    <a class="press-file"></a>
</div>
<div class="press-text">
    <h2></h2>
    <h3></h3>
    <p></p>
    <a class="press-file"></a>
</div>

私は次のjqueryを使用しています

$('.press-file').each(function(){
$(this).find('.press-text p').appendTo($(this));

しかし、何かが機能していません。

編集:私はこれをしようとしています

<p><a href="press-file></a></p>

最終的には。

4

1 に答える 1

6

.press-text要素を見つけるには、append代わりに、最も近いものを使用する必要がありappendToます。

$('.press-file').each(function(){
    $(this).closest('.press-text').find('p').append(this);
});

デモンストレーション(コンソールを開いて、変換された HTML を確認します)

于 2013-04-09T19:27:44.153 に答える