Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

205
Vistas
How to avoid .map skipping white spaces?

Got an issue. Need to put full name from array as ID of LI element. ATM it takes only first word for some reason.could you help?

const buddiesNames = ['RGX 11z Pro Buddy', 'Zedd Buddy', 'Get Carried Buddy', 'In A Bind Buddy', 'Year One Buddy'];

ulForBuddyNames.innerHTML = buddiesNames
  .map(
    (elem) =>
      `<li " class="valorantHeroBuddy"><a href="#"  onClick="showCharacterBuddy(event)" id=${elem}>  ${elem}<a/></li>`
  )
  .join('');

https://codepen.io/DeanWinchester88/pen/LYjmgyQ

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Can't have spaces in an id. Try replacing them with a hyphen: elem.replace(/\s+/, '-')

id's value must not contain whitespace (spaces, tabs etc.). Browsers treat non-conforming IDs that contain whitespace as if the whitespace is part of the ID. In contrast to the class attribute, which allows space-separated values, elements can only have one single ID value.

  • MDN

var ulForBuddyNames = document.querySelector('div');
const buddiesNames = ["RGX 11z Pro Buddy", "Zedd Buddy", "Get Carried Buddy", "In A Bind Buddy", "Year One Buddy"];
ulForBuddyNames.innerHTML = buddiesNames.map(elem => `<li class="valorantHeroBuddy"><a href="#"  onClick="showCharacterBuddy(event)" id=${elem.replace(/\s+/, '-')}>  ${elem}<a/></li>`).join("");
<div></div>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda