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

205
Views
Intentando agregar un lapso a un div existente obteniendo un error

Estoy tratando de agregar un lapso a un div existente, este es el código:

 const x = () => { const starsDiv = document.getElementsByClassName("wrapper"); const span = document.createElement("span"); let starsArr = []; let isHalf = false; let numberOfStars; for (let i = 0; i < starsDiv.length; i++) { starsArr.push(starsDiv[i].children); starsArr.map((item) => { const length = item.length; const starClass = item[item.length - 1].classList.value; isHalf = starClass === "fa fa-star-half-o" ? true : false; numberOfStars = isHalf ? length + 0.5 : length; }); span.innerHTML = numberOfStars; starsDiv.appendChild(span); } };

Recibo este error: TypeError no detectado: starsDiv.appendChild no es una función. ¡Espero que puedas ayudarme a resolver mi problema! gracias

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

0

El problema es que starsDiv no es un solo elemento. Según su código aquí:

 const starsDiv = document.getElementsByClassName("wrapper");

getElementsByClassName devuelve una HTMLCollection, incluso si solo se recupera un elemento: https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByClassName

Desde aquí, debe agregar el intervalo a un solo elemento. Qué elemento dependerá de su estructura HTML y dónde desea que aparezca el intervalo. appendChild hará que aparezca como el último hijo de un elemento.

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!