Sisi Sajah
Sisi Sajah

Reputation: 231

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

Upvotes: 3

Views: 3907

Answers (4)

CaptainHere
CaptainHere

Reputation: 698

See if this helps.

function testdemo() {
$('#test').html($('#test').text()).text();​
}

Upvotes: 0

Mayank Pandeyz
Mayank Pandeyz

Reputation: 26258

Try this:

JS:

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

Jquery:

function testdemo() {
   $('#test').html($('#test').text());
}

Upvotes: 3

Guruprasad J Rao
Guruprasad J Rao

Reputation: 29683

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>

Upvotes: 1

smarber
smarber

Reputation: 5074

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>

Upvotes: 0

Related Questions