jQuery.not()
と連鎖して使用することは可能jQuery.html()
ですか?
winner.not('a').html()
jQuery オブジェクト/ラップされたセットはどこにありますか?winner
アンカーを削除した HTML を返そうとしています。
.html()
innerHTML を返します - 内部に A タグが含まれますが、次のようなことができる場合があります。
// clone the matched div:
var copy = winner.clone();
// remove all A tags from the DOM
copy.find("a").remove();
// get the html.
var noanchors = copy.html();
また、A 自体ではなく A 内のテキストを取得したい場合は、次を使用できます。
// for each A tag
copy.find("a").each(function() {
//insert the text within ourselves to the document directly before us.
$(this).before($(this).text());
// then delete ourselves
$(this).remove();
});
<a>
に他のタグが含まれていると、実際には少し面倒になるかもしれませんが、アイデアを説明する必要があります。
可能ですが、期待する結果は得られません。コレクションからタグnot('a')
をフィルタリングしますが、コレクション内の最初のアイテムの値を返します。a
winner
html()
winner
を持っている場合、[div#i1 div#i2 a div#i3 a]
はこのセットをにnot('a')
減らし、の HTML コンテンツを返します。[div#i1 div#i2 div#i3]
html()
div#i1
.html()
HTML からアンカーを削除する場合は、まずメソッドを使用して取得し、返された値を正規表現で置換してアンカーを削除する必要があると思います。
または、次のようなものを使用できます。
var noanchors = '';
winner.not('a').each(function() { noanchors = noanchors + $(this).html(); )
非 a 要素の html の連結を取得します。ただし、これにより、さまざまなタグで囲まれたアイテム間のトップレベルのテキストが失われる可能性があります。