Answer the question
In order to leave comments, you need to log in
How to determine the number of DOM elements to the left of the caret in a div?
How to determine the number of DOM elements to the left of the active caret in ?
I searched everything already ...
Thanks in advance. <div contenteditable="true"></div>
Answer the question
In order to leave comments, you need to log in
Well, I have a slightly complicated method: you can try to iterate through the elements through a loop. As far as I know, JQuery and just JS do not seem to have fast functions for this.
window.getSelection().focusNode is the current element where the caret is set. Further, all options boil down to getting all the children of the contenteditable before this element. How to determine this is up to you, I would just compare the indices.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question