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

83
Visualizações
how can I select elements I created and appended with JavaScript?

essentially I created new divs through JavaScript. append them to a div container. and then try to select them all in JavaScript with the same class like this const cards=document.querySelectorAll('.card'); but it says its null

how can I select them all after I created them in JavaScript?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Since you haven't shared a sample yet, I followed the logic based on the information you provided and I created a small example of 2 div's appending them in another div. As you can see all the divs can be found in your container with console.log(document.getElementsByClassName('class')).

var div = document.createElement("div");
div.className = 'class'

var div2 = document.createElement("div");
div2.className = 'class';

var element = document.getElementById('id')
element.appendChild(div)
element.appendChild(div2)

console.log(document.getElementsByClassName('class'))
<div id="id"></div>

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