Javascript DOM HTML Textarea select() Method

Introduction

Select the contents of a text area:

document.getElementById("myTextarea").select();

Click the button to select the contents of the text area.

View in separate window

<!DOCTYPE html>
<html>
<body>

Address:<br>
<textarea id="myTextarea">
PO 1234, Main Street U.S.A.
New York</textarea>
<button type="button" onclick="myFunction()">Test</button>

<script>
function myFunction() {/*from   w ww  .ja va 2 s .co  m*/
  document.getElementById("myTextarea").select();
}
</script>

</body>
</html>

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

select();



PreviousNext

Related