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! While you're at it, check out some resources Treehouse students have shared here.

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

JavaScript

Why does AppendChild only show one child?

So I'm trying to make a simple loop through 3 children (each have 3 divs each to display). I can only get the 2 child to show.

My CSS has the area's overflow: hidden:

.carousel {
    margin: 0 auto;
    overflow: hidden;
    width: 1000px;
    height: 400px;
}

Here is my javascript for it:

carousel = document.getElementsByClassName('carousel')[0];
var next = document.getElementById('arrow-right');
var slides = document.getElementsByClassName('slides');


next.addEventListener('click', function () {
    for(let i =0; i<slides.length; i++){
        carousel.appendChild(slides[i]);
    }
})

Am I tackling this project the wrong way? I see so many answers on Stack Overflow using Jquery and a lot more complicated methods with lists and such. I feel as if this is more simpler, but if it won't work then I guess I have no choice.

1 Answer

Tiago Fernandes
Tiago Fernandes
3,647 Points

Hi mryoung, Could you link your workspace? So we can see your HTML source code. regards Tiago