Cursor Positioning in ContentEditable Div

99封情书 提交于 2019-12-11 12:06:53

问题


I have a contenteditable div where I catch certain words and wrap it with a span. And I try to do this while the user is typing.

Currently, I update the html content of the div by jQuery:

$(div).html($(div).html().replace(....))

However, the moment this is run, the cursor position in the div returns to the very first line.

Is there a different method in updating the contents of the contenteditable without losing the cursor position?

来源:https://stackoverflow.com/questions/20218043/cursor-positioning-in-contenteditable-div

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!