Can someone help me understand this bit of javascript. Determines caret position in a content editable div

var range = window.getSelection().getRangeAt(0); 
var preCaretRange = range.cloneRange();
preCaretRange.selectNodeContents(element); 
preCaretRange.setEnd(range.endContainer, range.endOffset); 
caretOffset = preCaretRange.toString().length;

caretOffset is the caret position of the content editable div, this bit of code doesn’t take into account line breaks however, something I’m hoping to make it do next, but first I need to understand what is going on here.

I search up “what is a javascript range” and I get hits for a slider like mechanism. Is getRangeAt related to this sliding element? Any advice?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.