Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

124
Views
js prevent blur from textarea

I am coding an editor, I have a menu tool bar, I want to keep my selection and cursor position in the textarea when I click on the toolbar. I have read most of relevant posts however none applies.

const app = document.querySelector('button');
const editor = document.querySelector('textarea');

// method 1 
/*
editor.addEventListener('blur', ()=>{
    editor.focus();
});
*/

// method 2
/*
app.addEventListener('click', e=>{
    e.preventDefault();
    e.stopImmediatePropagation();
    e.stopPropagation();
})
*/
<button>app</button>
<textarea></textarea>

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

From your question, you want to bring focus to text area when user clicks the button, below code provided, please let me know if this solves your issue.

const app = document.querySelector('button');
const editor = document.querySelector('textarea');

// method 1 
/*
editor.addEventListener('blur', ()=>{
    editor.focus();
});
*/

// method 2

app.addEventListener('click', e=>{
    e.preventDefault();
    e.stopImmediatePropagation();
    e.stopPropagation();
    editor.focus();
})
<button>app</button>
<textarea></textarea>

about 4 years ago · Juan Pablo Isaza Report

0

const app = document.querySelector('button');
const editor = document.querySelector('textarea');


// method 3

app.addEventListener('click', e=>{
    setTimeout(()=>editor.focus());
})
<button>app</button>
<textarea></textarea>

strong text

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!