select a word in textarea by javascript code example
Example 1: select all text in textarea javascript
<textarea onclick="this.focus();this.select()"></textarea>
<!-- To copy the text -->
<textarea onclick="this.focus();this.select();document.execCommand('copy')"></textarea>
Example 2: hi;ight word in textarea javascript
$(function(){
$("#search").click(function(){
var area = $('#test');
var findWord = "rhoncus";
var index = area.val().indexOf(findWord);
area.focus().prop({'selectionStart': index, 'selectionEnd': index+findWord.length})
})
})