I'm trying to insert div
with text to contenteditable
and select the text between the div tags after adding the div:
div.innerHTML +='<div id="id">selecttext</div>'
but this won't select the selecttext
<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>
Your question has three parts:
Is this what you need?
DEMO