ios - set cursor position in contenteditable div in uiwebview -


i loading uiwebview html file. html file contains text in div tags. need set cursor position in div tag. html file contains different div tags.based on condition need locate cursor position.

this helpful setting caret position.

suppose html this:

<div id="editable" contenteditable="true">   text text text<br>text text text<br>text text text<br> </div> <button id="button" onclick="setcaret()">focus</button> 

and javascript method is:

function setcaret() {     var el = document.getelementbyid("editable");     var range = document.createrange();     var sel = window.getselection();     range.setstart(el.childnodes[2], 5);     range.collapse(true);     sel.removeallranges();     sel.addrange(range);     el.focus(); } 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -