Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to control where the text cursor on div

function setCaret(row, col) {
    var el = document.getElementById("editable")
    var range = document.createRange()
    var sel = window.getSelection()
    
    range.setStart(el.childNodes[row - 1], col)
    range.collapse(true)
    
    sel.removeAllRanges()
    sel.addRange(range)
}
 
PREVIOUS NEXT
Tagged: #control #text #cursor #div
ADD COMMENT
Topic
Name
4+6 =