What is the easiest method to get the selection in input text field ?

Posted by Misha Moroshko on Stack Overflow See other posts from Stack Overflow or by Misha Moroshko
Published on 2010-05-17T13:03:15Z Indexed on 2010/05/17 13:10 UTC
Read the original article Hit count: 194

Filed under:
|
|
|

How could I get the selected text in the following code ?

I working with Firefox 3.6.3 (currently not interested in other browsers).

HTML:

<input id="my_text_field" type="text" />
<div id="log"></div>

JavaScript:

$("#my_text_field").select(function() {
   var selected_text = "Something selected"; // What should be here ?
   $("#log").append(selected_text + "<br />");
});

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JavaScript