Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get bold, italic styles within a div

Am working on a text editor where the content can be in the form of following

<div>some text <strong>bold text</strong> more <em>italic</em></div> 

Now on some user click, I have to remove the bold and italic styling from the div.

How can I remove the strong and em tags from a div?

Thanks

Kapil

like image 428
Kapil Gupta Avatar asked Dec 12 '22 13:12

Kapil Gupta


1 Answers

HTML

<div id="foo">
 <div>some text <strong>bold text</strong> more <em>italic</em></div> 
</div>

JS

var t = document.getElementById('foo').innerHTML;
t = t.replace('<strong>', '');
t = t.replace('</strong>', '');
t = t.replace('<em>', '');
t = t.replace('</em>', '');
document.getElementById('foo').innerHTML = t;
like image 122
JoJo Avatar answered Dec 30 '22 00:12

JoJo