You are looking for it
var strong=document.createElement("strong"); var range=window.getSelection().toString().getRangeAt(0); range.surroundContents(strong);
it was for the third part
You just need to choose what you want to use, using real user interaction.
If you want to do it dynamically
var range=document.createRange(); range.setStart(parentNode[textNode],index to start[X]) range.setEnd(parentNode[textNode],index to end[Y]) range.surroundContents(strong);
For the second part
range.deleteContents()
Part 1 can be done using a simple iteration
var textnode = // node of the element you are working with
textnode.splitText(offset)
offset-position, relative to which the text is split node [here == X] Two child nodes were created from the parent editable element
Now use a simple insertBefore () for the parent editable Node element.
hope you find it useful
source share