javascript - How to specifically set the caret position in a contenteditable div -
i need set caret position in contenteditable div in chrome not focused know caret position i.e. character index in html of div. div may have other elements inside of it.
the best got far setting caret position either @ end or start of div
domnode.focus(); if (window.getselection) { var sel = window.getselection(); //sel.collapsetostart(); //sel.collapsetoend(); sel.collapse(domnode, caretpos); } i tried calling 'modify' on selection manually move cursor word word , counting length of selected text text stops if there's element in way e.g. if div content "hello <span>world</span>" selected node's text hello .
Comments
Post a Comment