4

I have a <div> that has contenteditable="true" and after paste I'm sanitizing pasted content with Sanitize.js. The problem is, of course, that after Sanitization the cursor is put on the start of the div. How can I put cursor position after the pasted content?

HTML: <div contentEditable="true" id="ce"></div>

JS from Sanitize.js examples (modified):

function do_sanitize(){
    var elm = document.getElementById('ce');
    var cfg = Sanitize.Config.RELAXED;
    // Create new Sanitize object
    var s = new Sanitize(cfg);
    var cleaned_html = s.clean_node(elm);
    // Prepare container for sanitized HTML and append it
    var clean_container = document.getElementById('ce');
    while(clean_container.childNodes.length > 0) {
    clean_container.removeChild(clean_container.firstChild);
  }
  clean_container.appendChild(cleaned_html);
}
vsync
  • 118,978
  • 58
  • 307
  • 400
Santas
  • 421
  • 4
  • 11
  • 2
    I'm working on and have nearly finished a character-index based solution for this in [Rangy](http://code.google.com/p/rangy). In the meantime, you may find this helpful: http://stackoverflow.com/a/9841644/96100 – Tim Down Apr 21 '12 at 15:06

0 Answers0