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

257
Vistas
what is the fast and the easiest way to change the order of divs in html with javascript

I want to move div1 and div2 to the end of list

with only vanilla javascript

<div class="container">
   <div id="chlid-1"></div>
   <div id="chlid-2"></div>
   <div id="chlid-3"></div>
   <div id="chlid-4"></div>
   <div id="chlid-5"></div>
</div>
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Use CSS flex on a parent, and the order property on the desired child elements

.container {
  display: flex;
  flex-direction: column;
}

#child-1,
#child-2 {
  order: 1;
}
<div class="container">
   <div id="child-1">1</div>
   <div id="child-2">2</div>
   <div id="child-3">3</div>
   <div id="child-4">4</div>
   <div id="child-5">5</div>
</div>

Using JavaScript - use the Element.append() method like:

// DOM utils:

const ELS = (sel, par) => (par || document).querySelectorAll(sel);
const EL = (sel, par) => (par || document).querySelector(sel);


// Task:

EL(".container").append(...ELS("#child-1, #child-2"));
<div class="container">
   <div id="child-1">1</div>
   <div id="child-2">2</div>
   <div id="child-3">3</div>
   <div id="child-4">4</div>
   <div id="child-5">5</div>
</div>

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can do the following and the old div will be removed automatically

var element = document.getElementById('child1');
var parent = element.parentNode;
parent.insertAfter(element, parent.lastChild);
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