Skip to content Skip to sidebar Skip to footer

JavaScript / JQuery: Get Selection Function Not Working In Firefox And Chrome

I am using the following function to get the selected text (i.e. text selected by the user) in a contenteditable div. This works perfect in IE 9 but not in IE 8, Firefox or Chrome

Solution 1:

    function myGetSelection(){
         if(document.selection){ //IE
                return document.selection.createRange().text;
          } else{
                return window.getSelection().toString();
          }
   }

Post a Comment for "JavaScript / JQuery: Get Selection Function Not Working In Firefox And Chrome"