Javascript Reference - HTML DOM Textarea select() Method








The select() method selects the entire contents of a textarea.

Browser Support

select Yes Yes Yes Yes Yes

Syntax

textareaObject.select() 

Parameters

None.

Return Value

No return value.





Example

The following code shows how to select the contents of a textarea.


<!DOCTYPE html>
<html>
<body>
Address:<br>
<textarea id="myTextarea">
this is a test<!--from   w  w  w  .  j  ava 2  s .c  o  m-->
</textarea>
<button type="button" onclick="myFunction()">test</button>
<script>
function myFunction() {
    document.getElementById("myTextarea").select();
}
</script>
</body>
</html>

The code above is rendered as follows: