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

134
Vistas
Add complexe Javascript array elements to HTML

I want to add a complexe list item (a card with a picture, header, background etc.) for each element of an array. So far I created a .php template for the list elements.

This template is included in my html with the php include function

<ul id="kuchenListe">
    <?php include("cakeCard.php"); ?>                   
</ul>

and multiplied like this

function fillCakeList() {
    if (allCakes.length != 0) {
        var docFrag = document.createDocumentFragment();
        for (var i = 0; i < allCakes.length; i++) {
            var tempNode = document.querySelector("li[data-type='template']").cloneNode(true); 
            tempNode.querySelector("p.kuchenName").textContent = allCakes[i];

            docFrag.appendChild(tempNode);

        }
        kuchenListe.appendChild(docFrag);
        delete docFrag;
    }
}

I iterate through my array and include a new list element for each array entry which works fine.

The problem I am having is that this also includes the empty template in the beginning.

So I have two questions. First of all is this the right attempt at all to dynamically add array elements? And if yes. How do I not include the empty php template?

Thanks a lot.

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