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

84
Vistas
Create element inside another based on id

rigth now I have this code to draw some divs (based on some logic I'll have parent and childs.

array.forEach(async (a, b) => { 
    var currentDiv = 0;
    let divHtml;

    if (b === 0) {
        //This should be the first parent 
        divHtml = document.createElement('div');
        divHtml.id = 'someID' + currentDiv;
    } else if (previousDiv != currentDiv) {
        // This should be used for next parents based on the previousDiv & currentDiv logic
        divHtml = document.createElement('div');
        divHtml.id = 'someID' + currentDiv;
    } else {
        // This should be used only for childs. I want to create another div but inside the parent that I have stored into currentDiv.
        divHtml = document.getElementById('someID' + currentDiv);
        divHtml.id = 'someChildID' + currentDiv;
    }

    // Some more code below but what it's important is this (I continue using the divHtml in a lot of places on my code):
    divHtml.setAttribute('someData', someDataAttribute);
}); 

So, my question is: if there is a way to get the parentDiv and draw inside the X childs elements and how can I do it? I tried with this:

divHtml = document.createElement('div').appendTo($('#someID' + currentDiv));

But I'm getting the .appendTo() is not a function error message.

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

0

.appendTo() is a jQuery method, it seems you are using plain javascript, maybe you want to use append or appendChild

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