How to restore the cursor position after pasting in content and sanitation?

I have <div>one that has one contenteditable="true", and after pasting, I sanitize pasting content with Sanitize.js . The problem, of course, is that after sanitization, the cursor is placed at the beginning of the div. How to place cursor position after pasted content?

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

JS from Sanitize.js examples (changed):

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);
}
+3
source share

All Articles