javascriptrangy

rangy remove highlight after save the page


I can highlight the selected text and remove it.However, after highlighting the selected text I want to save page and I want to be able to select it and unhighlight it when I restore it. But rangy does not unhighlight when I reload the saved page. How can I do this ? My error : enter image description here


Solution

  • I solve this problem using jQuery like this :

    function unhighlight() {
        var range = window.getSelection().getRangeAt(0);
        var node = $(range.commonAncestorContainer)
    
        if (node.parent().is('span')) {
            node.unwrap();
        }
    }