In my project I am using a "contenteditable" div. I am trying to create an autocomplete functionality by using this div. Whenever I type any words, some suggestions should be visible in a different div. And when I press ENTER, the selected suggestion should be replaced with the entered text in the "contenteditable" div. Then when I press SPACE, further suggestions should be visible.
For a clearer explanation, please see this fiddle.
In the fiddle, type some letters and then press ENTER then SPACE.
Whenever I press SPACE, an alert box (for testing) will be displayed. This tells the current position of the caret in the "contenteditable" div.
But when I press ENTER and then SPACE, the current position of the caret is wrong, i.e. 0.
As far as I understood, if I don't use the placeCaretAtEnd() function then I am getting the caret position correctly. But in my case I want to use both (getCaretPosition() and placeCaretAtEnd()).
I am checking this in Firefox. (In Chrome, it seems to be working properly)
I need a solution that works in IE8+, Chrome and Firefox. Please help.