<div>
<span>
<span style="font-weight: bold;">MyName</span>
</span>
</div>
MyName の前後のスパンを削除し、最初のスパンを残すにはどうすればよいですか?
ありがとう
<div>
<span>
<span style="font-weight: bold;">MyName</span>
</span>
</div>
MyName の前後のスパンを削除し、最初のスパンを残すにはどうすればよいですか?
ありがとう
.contents()と組み合わせて.unwrap()を使用します。
$('#innerspan').contents().unwrap();
マークアップ:
<span>
<span id="innerspan" style="font-weight: bold;">MyName</span>
</span>
You can do next this time:
$('span').each(function() {
if ($(this).html() == "MyName") {
$(this).parent().html("MyName");
}
});
But it's very localized code.
文字列を要素に変換し、スパンのHTMLコンテンツを取得します。
s = $(s).html();