JSFiddle - React, Tailwind, and code Playground

HTML

<div class="editor" contenteditable=true>This is a contenteditable or editable div. This is actually a demo to help you understand my problem.<br><br><i>Place your caret</i> immediately above this line. Press any key and then open the console.</div>

JavaScript

var $div = document.querySelector("div");

$div.onkeydown = function(){
	var win = this.ownerDocument.defaultView,
    	sel = win.getSelection(),
        range = sel.getRangeAt(0);
        
    console.dir(range.startContainer);
    console.dir(range.startOffset);
};