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

185
Vistas
how to run onclick function with the dynamic string?

I am trying to get ID from an API (ID: food.slug) now as the value of the ID is string I am getting an error. index.html:1 Uncaught ReferenceError: apple_iphone_13_pro_max is not defined at HTMLButtonElement.onclick

This is the code

const showitem = (foods) => {
    const parent = document.getElementById('parent');
    for (const food of foods) {

        const newdiv = document.createElement('div');
        newdiv.classList.add('col')
        newdiv.innerHTML = `
      
        <div class="card" >
            <img src="${food.image}" class="card-img-top" alt="...">
            <div class="card-body">
                <h5 class="card-title">Card title</h5>
                <p class="card-text">This is a longer card with supporting text below as a natural lead-in to
                    additional content. This content is a little bit longer.</p>
            </div>

            <button onclick="singleitem(${food.slug})">details</button>
        </div>`;
        console.log(food.slug);

        parent.appendChild(newdiv);

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