Is there a way to get the current line (i.e. child div
), or current line number that the caret is on in a contenteditable
div
?
I’ve seen many solutions that can produce the index of the caret, or the total number of lines, but none that can get the specific line that is selected. The closest I’ve seen is this answer which works until the user updates the text.
One hurdle I see is that each new line creates a child div
element, except the first one. The initial text is part of the contenteditable
‘s direct innerHTML
. That is unless you delete the first line after creating a new one. In that case every line will have its own div
.