mardi 3 novembre 2020

Can we use getSelection and document.selection for spotting a word to delete it?

Can we use getSelection and document.selection for spotting a word to delete it? Is it possible to use them for this? The following code helps select words and put them in an array but the selected words remain in the text.

<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