我有一个段落标记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();':) –