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,
HT
I took this from another forum. It solved my problem.
Ok, I managed to work around it, here's the solution if anyone's interested:
Store the selection x, y:
Code:
cursorPos=document.selection.createRange().duplicate();
clickx = cursorPos.getBoundingClientRect().left;
clicky = cursorPos.getBoundingClientRect().top;
Restore the selection:
Code:
cursorPos = document.body.createTextRange();
cursorPos.moveToPoint(clickx, clicky);
cursorPos.select();
You can see it working here:
http://www.tachyon-labs.com/sharpspell/