1

Is it possible to activate to be able to write in a textarea, as soon as I click a button, without having to click on the textarea? Example: I have a button that makes a textarea appear, and when the text area appears I have to click it to start writing, what I was wondering if it is possible, when I click the button open the textarea and let me write without click on textarea

I'm using react

1 Answers1

1

You can set the focus on the text area once it's visible.

const button = document.getElementById('btn');
const textarea = document.getElementById('textarea');

button.addEventListener('click', () => {
  textarea.classList.add('visible');
  textarea.focus();
})
.hidden {
  display: none;
}

.visible {
  display: block;
}
<button id="btn" >Write</button>
<textarea id="textarea" class="hidden" name="" id="" cols="30" rows="10"></textarea>
Pistolpete .
  • 1,118
  • 1
  • 8
  • 17