Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Contenteditable - How to remove html tag with selection text

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

like image 927
Sisi Sajah Avatar asked Mar 17 '26 05:03

Sisi Sajah


1 Answers

Try this:

JS:

function testdemo() {
   var div = document.getElementById('test');
   div.innerHTML = div.textContent;
}

Jquery:

function testdemo() {
   $('#test').html($('#test').text());
}
like image 60
Mayank Pandeyz Avatar answered Mar 20 '26 16:03

Mayank Pandeyz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!