1

I have this setup:

<div contenteditable="true">
    <span>The quick brown fox </span>
    <span>jumps over the lazy dog.</span>
</div>

I need to be able to set the caret somewhere inside a span. I have found this How to set caret(cursor) position in contenteditable element (div)? which makes me able to set it inside a div, but not inside a span in the div.

Making the spans themselves contenteditable works, but I don't want that, because that way I lose the possibility to select over multiple spans.

General Grievance
  • 4,555
  • 31
  • 31
  • 45
  • http://stackoverflow.com/questions/16095155/javascript-contenteditable-set-cursor-caret-to-index – Tim Down Jul 08 '15 at 10:28
  • Hey @TimDown thanks for the link. It looks as your solution works with each subelement as a sepereate contenteditable, right? I want to avoid that, cause I want to be able to make selections over several subelements. – Jeroen Breen Jul 09 '15 at 11:29
  • No, the nested elements need not be contenteditable. However, I may have misunderstood exactly what you're asking. How exactly do you want to place the caret? – Tim Down Jul 09 '15 at 16:33
  • I am using the spans for styling. So I could end up with something like this:
    The quick brown fox jumps over the lazy dog.
    But the user would still need be able to select "fox jumps" and I need to be able to put the caret anywhere in any span (or over multiple spans)
    – Jeroen Breen Jul 09 '15 at 18:34
  • I did have a closer look at the linked examples and indeed they work as well with spans. Thanks! – Jeroen Breen Jul 10 '15 at 21:25

0 Answers0