document.getSelection() : getSelection « Document « JavaScript Tutorial






The getSelection() method returns the text that is selected within the HTML document.

<html>
    <form name="Form1">
      <input type="text"
             name="TextArea">
    </form>
    <script language="JavaScript">
    <!--

    document.captureEvents(Event.MOUSEUP);

    document.onmouseup = function(event){document.Form1.TextArea.value = document.getSelection()};

    -->
    </script>
    </html>








14.14.getSelection
14.14.1.document.getSelection()