I need another function that calls window.getSelection() so this needs to return an appropriate value based on the cursor position in the CED
Asked
Active
Viewed 549 times
4
-
3duplicate? ... http://stackoverflow.com/questions/1181700/set-cursor-position-on-contenteditable-div – Josiah Ruddell Jan 12 '11 at 22:02
-
The suggestion near the bottom does not seem to work for me. somehow, the offsets are reset to 0 by the time I access the saved range. – Ray Nicholus Jan 12 '11 at 22:28
-
Please clarify what you actually need to do, maybe with example code. Also, which browsers do you need to work with? – Tim Down Jan 12 '11 at 22:59
-
Chrome at this point, but that list may be expanded later. After deleting a contenteditable div, I need to reconstruct it, which includes placing the cursor in the same position it was in before the div was deleted. I have tried the example code in the link above in several different ways, but it doesn't seem to work. It doesn't seem like calling "addRange" on window.getSelection() has any effect. – Ray Nicholus Jan 12 '11 at 23:09
-
If the nodes the Range references in its `startContainer` and `endContainer` properties no longer exist, the Range adjusts itself. – Tim Down Jan 16 '11 at 01:13
-
This is one of the hardest things to do in JS, cross browser. I highly recommend you use existing libraries (like rangy) and work your UI around the limitations. – mwilcox Feb 13 '11 at 19:20
1 Answers
0
I think this is as good as you're going to get... Set cursor position on contentEditable <div>

Community
- 1
- 1

SavoryBytes
- 35,571
- 4
- 52
- 61