Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Jesus Mendoza
Jesus Mendoza
23,288 Points

I'm trying to do a slider with jQuery

I have a bit of troubles, when I hit the previous button it's suppose to go to the last slide if i'm on the first. (It works with the next button but not with the previous) Anyone knows what's wrong?

  // Previous button is clicked
  $('span.prev').on('click', function() {
    // remove class to current item and add class oldActive to know this was the last slide shown
    // if oldActive was the last-child go to the first one
    if ( $('.oldActive').is(':first-child') ) {
    } else {
      // if oldActive was not the last-child, then add class to the previous one
    // Clear oldActive class

Here is the pen http://codepen.io/Jesusz0r/pen/mVdxEL?editors=101

1 Answer

Melissa Austin
Melissa Austin
3,383 Points

It appears you were able to get it working in the CodePen.

Jesus Mendoza
Jesus Mendoza
23,288 Points

Yeah I did after hours hahaha