I need to get the text (or all internal html) of a node truncated to the current cursor position (text cursor) in an element with contenteditable set to true . I tried using range.setStart () etc., but I can not make heads and tails ...
Edit: To clarify some events, I want the script to retrieve text from the beginning of the node, which currently has focus on the caret position (where the blinking vertical line is currently located if the editable field has focus) and save it in Variable . The action is similar to what would happen if the user pressed ctrl + shift + home and ctrl + c
Example: Given html:
<span contenteditable=true>Hello, world<br> Good bye, World</span>
And assuming the carriage is between βgoodβ and βgoodbye,β I would like to get
"Hello, world<br> Good"
source share