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

104
Vistas
Jquery insert element in middle of siblings?

I have the following html

<ul class ="paragraphs">
  <li class="paragraph" element="1">1</li>
  <li class="paragraph" element="2">2</li>
  <li class="paragraph" element="3">3</li>
  <li class="paragraph middle" element="4">4</li>
  <li class="paragraph" element="5">5</li>
  <li class="paragraph" element="6">6</li>
  <li class="paragraph" element="7">7</li>
</ul>

I have a variable which is a random element (element="1" to element="7"), I am trying to position that element in middle, but keep other elements in order. So if the element was 2, the order would be 1342567, if the element was 7 the order is 1237456.

I start by removing the middle class

$(".paragraphs middle").removeClass("middle");

I then add .middle to the given element

$(".paragraphs .paragraph[ element=' + Element + ']").addClass("middle");

What I am trying to do now is add the .paragraph.middle in to the middle of the children? One way I was thinking is to check if the element is between 1-4 if so then insert after 4, If the element is between 4-7 then insert before the middle. But wondering if this is the best way, or if there is anything simpler?

Thanks

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