how to remove html tag in contenteditable
with selection text
function testdemo() {
//what is next
....
}
Before :
<button onclick="testdemo();">RUN</button>
<div id="test" contenteditable="true">
<b>Lorem ipsum</b> dolor sit amet, <span style="color:red;">ea ignota verear</span> quaerendum
</div>
After :
<div id="test" contenteditable="true">
Lorem ipsum dolor sit amet, ea ignota verear quaerendum
</div>
Thank you in advance
Try this:
JS:
function testdemo() {
var div = document.getElementById('test');
div.innerHTML = div.textContent;
}
Jquery:
function testdemo() {
$('#test').html($('#test').text());
}
jQuery version would be as below:
function testdemo() { $("#test").html($("#test").text()); }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <button onclick="testdemo();">RUN</button> <div id="test" contenteditable="true"> </div>
function testdemo() { var div = document.getElementById('test'); div.innerHTML = div.textContent; }
<button onclick="testdemo();">RUN</button> <div id="test" contenteditable="true"> <b>Lorem ipsum</b> dolor sit amet, <span style="color:red;">ea ignota verear</span> quaerendum </div>
See if this helps.
function testdemo() {
$('#test').html($('#test').text()).text();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.