When you click on a button, a block (with the contenteditable attribute) is placed in the name and wrapped in element b and then you need to type after the name, if you then click in this block, the cursor does not extend beyond the b element and you get all the printed text in bold too, How to display the cursor for this item?
Why the selectionStart does not work.
<p style=" padding: 10px; background: white; width: 50%;" contenteditable="true" class="write-comment"></p> var formComment = document.querySelector('.write-comment'); var userNameHtml = document.createElement('b'); userNameHtml.innerHTML = userName + ', '; formComment.appendChild(userNameHtml); formComment.focus();formComment.selectionStart = formComment.innerHTML.length;