JSFiddle - React, Tailwind, and code Playground

HTML

<button onclick="testfunction()">test</button>
<div id="divT" spellcheck="false" contenteditable="true"></div>

JavaScript

document.getElementById("divT").innerHTML = "bla bla bla";

function testfunction() {
	try {
		if (window.getSelection && (sel = window.getSelection()).modify) {
			var s = window.getSelection();
			var range = s.getRangeAt(0);
			range.collapse(true);
		}

	}
	catch(err) {
		alert(err);
	}
}