Languages
[Edit]
EN

JavaScript - how to make focus on textarea element?

5 points
Created by:
Kate_C
19800

Using JavaScript it is possible to get focus on textarea element in following way.

1. Pure JavaScript approach example - VanillaJS

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<body>
  <textarea id="my-input" cols="30" rows="4">
This is example text...
  </textarea>
  <br />
  <button onclick="makeFocus()">Click me and make focus on textarea</button>
  <script>
    
    var input = document.getElementById('my-input');

    function makeFocus() {
    	input.focus();
    }
   
  </script>
</body>
</html>

2. jQuery approach example

Read this article to see jquery approach.

Native Advertising
50 000 ad impressions - 449$
🚀
Get your tech brand or product in front of software developers.
For more information contact us:
Red dot
Dirask - friendly IT community for everyone.

❤️💻 🙂

Join