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

166
Views
Access EventTarget of addEventListener without using a variable

This codes removes the focus from the select element after you click it:

const select = document.querySelector('select');
select.addEventListener('focus', () => {
  select.blur();
});
<select>
  <option>Option 1</option>
  <option>Option 2</option>
</select>

Is it possible to change it so that it won't be necessary to assign a constant/variable first?

Something like this:

// pseudocode
document.querySelector('select').addEventListener('focus', () => {
  EventTarget.blur();
});

(And of course, I don't mean

document.querySelector('select').addEventListener('focus', () => {
  document.querySelector('select').blur();
});

)

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

0

yes it is possible. just modify your code a bit.

document.querySelector('select').addEventListener('focus', (e) => {
  e.target.blur();
});
<select>
  <option>Option 1</option>
  <option>Option 2</option>
</select>

about 4 years ago · Juan Pablo Isaza Report

0

You can do it with event.target from function params

document.querySelector('select').addEventListener('focus', (event) => {
  event.target.blur();
});
<select name="cars" id="cars">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value="audi">Audi</option>
</select>

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!