1

HTMLコード

<article class="evn-mn-pane">
    <h2><a href="somelink.php">leborium</a></h2>
    <div class="evn-date">20 June, 2013 |  Dr.some name some name1</div>
    <figure>
        <img src="images/events/speakers/no-image.jpg" alt="Dr. Somename"/>
            <figcaption>test link tested some dummy text this...
                <a href="somlink.php">more</a>
            </figcaption>
            <div class="clear"></div>
    </figure>
</article>

<article class="evn-mn-pane">
    <h2><a href="somelink.php">leborium</a></h2>
    <div class="evn-date">20 June, 2013 |  Dr.some name some name1</div>
    <figure>
        <img src="images/events/speakers/no-image.jpg" alt="Dr. Somename"/>
            <figcaption>test link tested some dummy text this...
                <a href="somlink.php">more</a>
            </figcaption>
            <div class="clear"></div>
    </figure>
</article>

Jクエリコード

$('article').each(function(){
    alert($(this).find('figure > figcaption').html());
});

結果

テストリンクは、これをいくつかのダミーテキストでテストしました...

          <a href="somlink.php">more</a>

期待される結果

テストリンクは、これをいくつかのダミーテキストでテストしました...

このSOリンクを試しました

試したコード

$('article').each(function(){
    alert($(this).find('figure > figcaption').contents(':not(a)').html());
});

結果の取得

未定義

JSFIDDLE

期待される結果を得るにはどうすればよいですか?

アップデート

アンカータグ以外のすべてのタグを取得し、クローンメソッドを使用する以外の結果を期待したいと思います。

4

4 に答える 4

0

次のように検索して削除aします (HTML からリンクを削除しないように更新):

$('article').each(function(){
    var div = $("<div>" + $(this).find('figure > figcaption').html() + "</div>");
    div.find('a').remove();
    alert(div.html());
});

jsフィドル

于 2013-07-16T05:40:03.800 に答える
0

テキストは最初の childNode です:

$('article').each(function(){
    console.log($(this).find('figure > figcaption')[0].childNodes[0].data);
});

フィドルのデモ

于 2013-07-16T05:41:42.443 に答える