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

186
Views
How can I delete multiple DIV ids all at once with console?

anyone knows how can i delete multiple div IDs all at once with a command in console? Thanks

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You can remove an element using Element.remove(). Just call that method on each element that you want to remove.

For selecting multiple elements, you can use Document.querySelectorAll() with a CSS selector which matches the elements that you are targeting.

// You didn't show in your question which elements
// you want to select, so here's an example:
function getElements () {
 return document.querySelectorAll('li.even');
}

function removeEven () {
  const elements = getElements();

  for (const element of elements) {
    element.remove();
  }
}

const button = document.querySelector('button.remove');

button.addEventListener('click', removeEven);
<div>
  <ol>
    <li class="odd">A</li>
    <li class="even">B</li>
    <li class="odd">C</li>
    <li class="even">D</li>
  </ol>  
</div>
<div>
  <button class="remove">Remove even elements</button>
</div>


Update in response to your comment:

document.querySelectorAll('#id-a, #id-b, #id-c').forEach(elm => elm.remove());
about 4 years ago · Santiago Trujillo Report

0

Try writing a quoted, comma separated list of id values. Add a call to split at the commas, followed by a forEach clause to remove the elements. If you're like me and throw in spaces as well, trim the id value as well.

E.G. to delete divs with ids divA, divB, divC, mydiv, yourDiv, theirDiv, execute

"divA, divB, divC, myDiv, yourDiv, theirDiv".split(',').forEach( id=>document.getElementById(id.trim()).remove() )

on the console. If you do it often, keep most of the text separately.

about 4 years ago · Santiago Trujillo 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!