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

210
Visualizações
Javascript get Last DIV element in Body

If I had div's without id's or anything, but with the information that it is the last thing before the tag, is there a way I can use javascript to delete it? Example:

<body>
<div>don't delete</div>
<div>don't delete</div>
<div>don't delete</div>
<div>delete this div</div>
</body>

Thanks (I'm sorry if my question sucks, please tell me how I can improve it)

I also would not like to use jQuery

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can also use a plain CSS selector to get the last div immediately, instead of retrieving a collection.

document.querySelector('body > div:last-of-type').remove();
<body>
  <div>don't delete</div>
  <div>don't delete</div>
  <div>don't delete</div>
  <div>delete this div</div>
</body>

about 4 years ago · Juan Pablo Isaza 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