JSFIDDLE要素からテキストを正しく取り出して要素を破壊する方法は?
私は段落タグに2(それ以上)のhighlight
タグを付けました。
ここをクリックしてボタンをクリックすると、highlight
タグを使用せずに 'リムーバブル'テキストが破棄され、プレーンテキストが 'リムーバブル'に置き換えられます。属性。
HTML:
<p>
<highlight class="highlight" data-id="1464586442243" data-container="body" data-toggle="popover" data-placement="right" data-content="<p>first</p><button class="btn edit_annotation" data-id="1464586442243">Edit</button>&nbsp;<button class="btn delete_annotation" data-id="1464586442243">Delete</button>"
id="anchor_1464586442243" data-original-title="" title="">Section</highlight> 1
<highlight class="highlight" data-id="1464586450092" data-container="body" data-toggle="popover" data-placement="right" data-content="<p>second</p><button class="btn edit_annotation" data-id="1464586450092">Edit</button>&nbsp;<button class="btn delete_annotation" data-id="1464586450092">Delete</button>"
id="anchor_1464586450092" data-original-title="" title="">removable</highlight> true</p>
<button id="remove" type="button">Remove</button>
JS:
$(function() {
$('#remove').click(function() {
// i stuck here
});
});
期待される結果:
<p>
<highlight class="highlight" data-id="1464586442243" data-container="body" data-toggle="popover" data-placement="right" data-content="<p>first</p><button class="btn edit_annotation" data-id="1464586442243">Edit</button>&nbsp;<button class="btn delete_annotation" data-id="1464586442243">Delete</button>" id="anchor_1464586442243" data-original-title="" title="">Section</highlight> 1 removable true
</p>
はどのようにそれを行うには?私はhereのように.contents().unwrap()
を使ってみましたが、それは私にとってはうまくいかなかったのです。
<p><highlight class="highlight" data-id="1464586442243" data-container="body" data-toggle="popover" data-placement="right" data-content="<p>first</p><button class="btn edit_annotation" data-id="1464586442243">Edit</button>&nbsp;<button class="btn delete_annotation" data-id="1464586442243">Delete</button>" id="anchor_1464586442243" data-original-title="" title="">Section</highlight> 1 remov<highlight></highlight>able true</p>
ありがとうございました。これは私が '$(this).before($(this).html()).remove();' :)を探しています。 –