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

123
Views
Cómo puedo obtener la API correctamente

Creé 10, cada uno muestra una identificación en la API. Utilicé querySelectorAll para encontrar todos los bucles y uso for para hacer que el contenido de cada uno contenga una identificación en la API, pero cuando intento codificar, como puede ver, una contendrá las diez identificaciones y no sé cómo hacer es posible

 function onResponse(response) { return response.json(); } function data(data) { //create a function to display the element var htmls = data.map(function(post) { return `<li> <h2> ${post.id}</h2> </li>` }); var html = htmls.join(''); const p = document.querySelectorAll('span'); for (let i = 0; i < p.length; i++) { p[i].innerHTML = html; } } fetch('https://jsonplaceholder.typicode.com/users').then(onResponse).then(data);
 <body> <form> <div> <span></span> <span></span> <span></span> <span></span> <span></span> <span></span> <span></span> <span></span> <span></span> <span></span> </div> </form> </body> </html>

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

0

html ya es el HTML de cada id . Lo está asignando al innerHTML de cada span , lo que hace que haya 9 duplicados.

En su lugar, simplemente asigne al innerHTML span

 function onResponse(response) { return response.json(); } function data(data) { //create a function to display the element var htmls = data.map(function(post) { return `<li> <h2> ${post.id}</h2> </li>` }); var html = htmls.join(''); const div = document.querySelector('div'); div.innerHTML = html; } fetch('https://jsonplaceholder.typicode.com/users').then(onResponse).then(data);
 <body> <form> <div> <span></span> <span></span> <span></span> <span></span> <span></span> <span></span> <span></span> <span></span> <span></span> <span></span> </div> </form> </body> </html>

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!