Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

132
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!