mardi 3 novembre 2020

How to delete the selected words in the text?

This code selects words and makes an array from them. But I need to delete words after being selected and added to the array. I think I need to work with either document.getSelection() or document.selection, but I don't know how to delete the selected words through them. I would be happy if anyone gave me a hint.

<script>
let container;
var arr = [];
function get_selection() {
  
    var txt = '';
       if (document.getSelection) {
          txt = document.getSelection().toString();
                
                
            } 

            else if (document.selection) {
                txt = document.selection.createRange().text;
            }
             arr.push(txt);
            }
            }
           document.getElementById("txt").onclick = get_selection;

</script>

Aucun commentaire:

Enregistrer un commentaire