I have been struggling the selectionStart and selectionEnd attributes of textarea to make them work with contenteditable div element. I have checked a lot of related articles on google and on SO but to no avail. I have something similar to the following which is working for textarea perfectly. But I want this one to work with contenteditable div.
function replaceVal(node, val, step){
//...
var cursorLoc = node.selectionStart;
node.value = node.value.substring(0, node.selectionStart - step) + value +
node.value.substring(node.selectionEnd, node.value.length);
node.scrollTop = scrollTop;
node.selectionStart = cursorLoc + value.length - step;
node.selectionEnd = cursorLoc + value.length - step;
//...
}
How can this be modified so that it will work with contenteditable div element instead of textarea?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…