I have a simple contenteditable div with some text in it. On onkeyup event i want to replace whole content (innerHTML) of the div based on regex.
For example,
HTML:
some text, more text and $even more text
Function in which i plan to get all text with $ ($even in example above) and wrap it in span tag:
div.onkeypress = function() {
div.innerHTML.replace(/(some_regexp)/, "<span class='class'>$1</span>");
};
The problem is after such replacement cursor jumps to the start of the div. I want it to stay where it was before.
I imagine i have to save coordinates of the cursor before change and then somehow using them set cursor back but how can i do it? :)
I tried saving range object but after editing i believe it points to nowhere.
Thanks!