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.

Hey 👋
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.