I have a <div />
which is contenteditable
and can contain several types of HTML elements such as <span />
, <a />
, <b />
, <u />
and so on.
Now when I select text in my contenteditable
I would like to have a button that removes all the styles within the selection.
Example 1:
The Selection:
Hello <b>there</b>. I am <u>a selection</u>
would become:
Hello there. I am a selection
Example 2:
The Selection:
<a href="#">I am a link</a>
would become:
I am a link
You get the idea...
I have found this helpful function https://stackoverflow.com/a/3997896/1503476 which replaces the current selection with custom text. But I just cannot get the content of the selection first and strip the tags out before replacing it. How can I do that?