JavaScript - how to make focus on textarea element?

5 points
Created by:

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>
  <textarea id="my-input" cols="30" rows="4">
This is example text...
  <br />
  <button onclick="makeFocus()">Click me and make focus on textarea</button>
    var input = document.getElementById('my-input');

    function makeFocus() {

2. jQuery approach example

Read this article to see jquery approach.

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

JavaScript - DOM Node - problems & solutions

Native Advertising
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂