Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

209
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda