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

228
Visualizações
Trying to remove a paragraph in JavaScript

I am doing an assignment where I'm meant to remove a paragraph from the page when a button is clicked. I keep returning an error "Uncaught TypeError: Node.removeChild: Argument 1 is not an object." and it references line 37 in my code.

Line 37: divTag.removeChild(divTag.children[allPs.length-1]);

This is part of a script:

btnDelete.addEventListener('click', function(){
      var allPs = document.querySelectorAll('p');
      divTag.removeChild(divTag.children[allPs.length-1]);
    });
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

One important thing to consider is that divTag.children, which looks at the children of one element in the DOM, may be considerably shorter than allPs.length, which as you've defined it is all the p elements in the DOM. What's probably actually causing the error is that you're looking at an index ([allPs.length - 1]) that doesn't exist in the array divTag.children. I don't know the exact spec of what you're working on, but you can try replacing divTag.children[allPs.length - 1] with allPs[allPs.length - 1]. Without more info on what the actual spec is that's about as helpful as I can be for now. If you have more info I can elaborate in a comment.

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