how to control where the text cursor on div

Solutions on MaxInterview for how to control where the text cursor on div by the best coders in the world

showing results for - "how to control where the text cursor on div"
Cam
16 Nov 2020
1function setCaret(row, col) {
2    var el = document.getElementById("editable")
3    var range = document.createRange()
4    var sel = window.getSelection()
5    
6    range.setStart(el.childNodes[row - 1], col)
7    range.collapse(true)
8    
9    sel.removeAllRanges()
10    sel.addRange(range)
11}