Is there a way to add a div
with text to a contenteditable
element and automatically select the text between the div tags after inserting the div?
div.innerHTML +='<div id="id">selecttext</div>'
I have tried this method, but it does not seem to select the specific text as intended.
<html>
<head></head>
<body>
<div id="contenteditable" contenteditable></div>
<script>
var contenteditable = document.getElementById("contenteditable");
contenteditable.onkeyup = function (e) {
contenteditable.innerHTML += '<div>Start here</div>';
}
</script>
</body>
</html>