Question

When I select string (word) by doubleclick in textarea, then always select word and white space after text.

Maybe it's trivial question, but how to select text by doubleclick without white space after word?

Was it helpful?

Solution

I have this solution see example below. What is your opinion?

<html>
<body>
<textarea cols=50 ondblclick="checkDblClick(event)">abc1space abc2space  abc3space   abc
</textarea>
<script>


function checkDblClickDelayed(target) {

    while (target.value.substr(target.selectionEnd -1, 1) == " ")  {
      target.selectionEnd = target.selectionEnd - 1;
    }
}

function checkDblClick(e) {
//we make a delay of 0ms to wait until the selection is in the final position
    target = e.target;
    setTimeout(function()
            {   
        checkDblClickDelayed(target); 
        }
        , 0);
}


</script>

</body>
</html>

OTHER TIPS

The answer is... you can't.

The closest you can get is double clicking the text, and then Shift+Clicking it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top