我有一個段落標記2(可以更多)highlight
裏面的標籤。
我現在想要做的是,當我點擊按鈕時,我希望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>
怎麼辦呢?我嘗試使用.contents().unwrap()
像提到的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();':) –