Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Online jQuery Editor

<html>
    <head>
        <title>Check it </title>
         <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
             $(document).bind('mouseup', function(){
             var content =  getSelected();
                console.log(content)
            });
    });
       
        function getSelected(){
            var t;
            if(window.getSelection){
               t = window.getSelection();console.log(t)
               var start = t.focusOffset;
               var end = t.baseOffset;
               t = t.anchorNode.data;
               console.log(String(t).slice(start, end))
            } else if(document.getSelection){
                t = document.getSelection()
            }  else if (document.selection) {
                 t = document.selection.createRange().text;
            }
            return t;
        }
    </script>
    </head>
   
    <body>
        <div>sdjkfsdh fkljsd fkjsd<br>sdfsdjklfhsdlkjfhsdklfjs<br>sflk;sdjfsdkl;fjsdl;fjkl;</div>
    </body>
</html>

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.