views:

642

answers:

2

By default, when one double click on a word in a textarea, it will select the word AND the space after the word.

Is there a js script that can allow user to double click on a word and select ONLY the word, without the space that follows?

I've been searching high and low with no luck.

+3  A: 

You could add a double click event to the textarea, get the selected word, trim whitespace and then return the trimmed selected word to the user. I'm not sure if there is a better way but thats how I will probably approach it.

Christian
+1  A: 

+1 to Christain'n answer...

But I would add:

The double clicking behaviour may on the OS/Browser being used. A word might not be selected by double clicking on it.

Example: on windows, clicking on the address bar selects all the text but on linux, the same does not happen. I know that the browser's text field is not the same as ones rendered in HTML, but it serves to demonstrate the text field behaviour is not entirely predictable.

Here Be Wolves