Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

226
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!