Your slides
variable is not an Array
, but a jQuery object.
.eq()
returns a jQuery object, eventually empty if index
is out of bounds, and a negative index
is counted from the end.
.get()
returns a DOM Element, or undefined
if index
is out of bounds, and a negative index
is counted from the end.
[]
returns a DOM Element, or throw an Error if index
is out of bounds.
...
Additionally, jQuery methods let you interact with a set of elements as it was alone. So you if you do:
slides.css("left", "-100%");
It is applied on every matched elements contained in the jQuery object. It is unnecessary to loop over them.
...
Also the preferred way to loop over matched elements is using the each()
method:
slides.each(function (i, el) {
var $el = $(el);
});
...
Also it is an established convention to prefix jQuery variables with a $
sign; it let you to easily differentiate DOM elements from jQuery objects. But that's only a matter of taste.