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

224
Vistas
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 Respuestas
Responde la pregunta

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 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