I want to create a simple WYSIWYG editor with contenteditable and a bold option. This used to be really easy to achieve using execCommand as can be seen here.
Unfortunately execCommand is now deprecated.
My approach to achieve this without execCommand would be the following:
- Get selection with window.getSelection()
- Convert the selection to a text node on which I can set innerHTML and make sure it is a descendant of the contenteditable div
- Do a simple transform of the innerHTML (e.g.
node.innerHTML = '<b>' + node.innerHTML + '</b>'
)
However, I am not sure how to achieve the second part. window.getSelection().anchorNode
returns the correct node, but it won't let me set innerHTML or innerText on it.
Is this even possible? Thanks in advance!