Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

90
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda