Answer the question
In order to leave comments, you need to log in
How to put the cursor at the end of the text (Javascript)?
There is an html element:
<div contenteditable="true" class="test">Некоторый текст</div>
var list = document.getElementsByClassName('test');
function msgUpd(){
for(i=0;i<list.length;i++){
var rep = list[i].innerText.replace('Заменяемый текст','Замена');
if(list[i].innerText != rep){
list[i].innerText = rep;
console.log('Replaced');
}
}
}
setInterval(msgUpd,500);
Answer the question
In order to leave comments, you need to log in
For the lazy, I'll just throw the qwer code here :)
var input = document.querySelector("input");
input.focus();
input.selectionStart = input.value.length;
As far as I know, the cursor is placed by setting the selection to zero length. Those. look for how to select part of the text in the input field.
make it on the input change event and you will not have to bother and everything will be replaced during the input process and not by timeout Example
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question