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

188
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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