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

210
Views
Cómo agregar un detector de eventos para las opciones de la lista de datos

¿Puede alguien decirme por qué mi código no funciona? En particular, hacer clic en la opción no funciona

 let apiUrl = 'https://jsonplaceholder.typicode.com/todos'; // for test let input = document.querySelector('.address'); let dataList = document.querySelector('#suggestions'); input.addEventListener('input', e => { let fragment = document.createDocumentFragment(); fetch(apiUrl) .then(response => response.json()) .then(addresses => { addresses.forEach(address => { console.log(address.title); let option = document.createElement('option') option.setAttribute('value', address.title); option.addEventListener('click', e => console.log('Hi!')) fragment.append(option); }) }) dataList.innerHTML = ''; dataList.append(fragment); });
 <input class="address" type="text" list="suggestions"> <datalist id="suggestions"></datalist>

about 4 years ago · Juan Pablo Isaza
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!