How can I set the cursor after a span element inside an contenteditable div? Right now, I've an image inside a span element, inside the contenteditable div.
When I add some characters, they are added inside the span, but I want them to be added after the span element. Any ideas how I can achieve this?
In browsers other than IE <= 8, this will do it:
However, some browsers (notably WebKit-based ones) have fixed ideas about which positions in the document are valid for the caret and will normalize any range you add to the selection to comply with those ideas. The following example will do what you want in Firefox and IE 9 but not in Chrome or Safari as a result:
http://jsfiddle.net/5dxwx/
None of the workarounds are good. Options include:
<a>
element instead of a<span>
because WebKit makes an exception for<a>
elementsI managed to solve this problem using 'a' tag with
 
. Example :-"<a>"+ content/element you want to add +"</a> "
This function manages what I had in mind:
Just
span.contentEditable = false
to Tim's solution work properly ;)