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

151
Views
How to remove an element if it contains a link using querySelectorAll?

I tring to remove all list items that contain a link But I only remove the child element and don't know how to remove the parent.

document.querySelectorAll('li a[href^="/chennal/robin"').forEach(e => e.remove());

I tried to do it with loops, but it seems I'm just complicating the code for no reason, especially since it doesn't work.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

So you need to walk up the DOM tree back up to the li and remove that.

You either need to use parentNode or parentElement if it is one element up. Or closest('li') if it is more than one element up.

e.parentNode.remove();
e.parentElement.remove()
e.closest('li').remove();
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!