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

134
Vistas
Automatic Carousel with Dom manipulation

I want to change the order of my child divs in the parent div, every 2 seconds with no interactions (rotate by its self if page is loaded:

First child needs to move to third child, second child needs to move to the first child and the third child needs to move to the second child

The second and third child should always have the class "small" and when it reach the first child position it should be removed.

HTML

     <div class="inner-testimonial">        
         <div class="slide">
             <h4>Copy here</h4>
         </div>
         <div class="slide small">
             <h4>Copy here</h4>
         </div>
         <div class="slide small">
             <h4>Copy here</h4>
         </div>
      </div>

JQuery

$(".inner-testimonial .slide:nth-child(1)").removeClass('small');
$(".inner-testimonial .slide:nth-child(2)").addClass('small');
$(".inner-testimonial .slide:nth-child(3)").addClass('small');

How can I do this?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can do it like this :

  1. Remove small class for all slides with removeClass()
  2. Set different var with each slides positions
  3. Set slides container empty with empty()
  4. Append slides in right order with append()
  5. And then add all of this inside a setInterval() called every 2 seconds.

Order of first change will be : 2 3 1
Order of second change will be : 3 1 2
And then order will return to its initial point : 1 2 3

Thanks to validate and upvote my answer if it do what you expect.

setInterval(function () {
  // remove small class for all slides
  $('.inner-testimonial .slide').removeClass("small");

  // set different var with each slides positions
  var firstEl = $('.inner-testimonial .slide:first');
  var secondEl = $('.inner-testimonial .slide:first').next();
  var thirdEl = $('.inner-testimonial .slide:last');

  // set slides container empty
  $('.inner-testimonial').empty();

  // append slides in right order : secondEl + thirdEl + firstEl
  $('.inner-testimonial').append(secondEl);
  $('.inner-testimonial').append($(thirdEl).addClass("small"));
  $('.inner-testimonial').append($(firstEl).addClass("small"));
}, 2000);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="inner-testimonial"> 
  <div id="first"></div>
   <div class="slide">
       <h4>First</h4>
   </div>
   <div class="slide small">
       <h4>Second</h4>
   </div>
   <div class="slide small">
       <h4>Third</h4>
   </div>
</div>

<div id="test"></div>

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