Q:

Click elements with javascript

Trying to make a simple loop for a carousel to slide the images automatic but can't figure out why it doesnt work... Any help is appreciated, (the 'dot' is what you click at when you want to change picture in the carousel) but I want the slides to change automatically when the page is visited.
the code looks like this: 
window.setInterval(slideClick, 2000);

var slides = document.getElementsByClassName('dot');

    for(var i = 0; i < 6; i++ ) {
        function slideClick() {
        slides.click();

        }
    }

    if (i === slides.lenght) {
        i=0;
    }

I get this error: Object # has no method 'click'
and if I change slides.click(); to the classname $('.dot').click it works but only for the two first slides?

A:

document.getElementsByClassName which you use to obtain slides returns a NodeList, it's a list of nodes, not a single element.
HTMLElement#click() is a method of a single element. You can iterate the returned NodeList and call it on each returned value.

One way is:
for(var j = 0; j < slides.length; j++) slides[j].click();

