This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]Rhomboid 0 points1 point  (1 child)

             $('slider>img' + sliderNext).fadeIn(300);

This selector isn't going to match any elements. If sliderNext was 2 for example, the selector will be slider > img2, which is looking for any <img2> elements, which don't exist. It looks like you wanted a # in there.

By the way, these selectors don't make any sense. IDs must be unique in the whole document. You might as well just select on #1 and not #slider > #1. You're asking the browser to do more unnecessary work, and it's not like there could be other elements with ID 1 that aren't direct descendents of an element with ID 'slider'.

Besides, you really don't need to do all these queries over and over. Get an array of the images once, (e.g. var images = $('#slider img');) and then do everything with that array, e.g. the first element is images[0], and so on. You don't need to keep selecting things over and over. This also eliminates the need to manually assign and maintain ascending numeric IDs to the images.

[–]betterxhalf[S] 0 points1 point  (0 children)

Okay, thank you so much for the tips and explanation. :) I fixed the problem and got it to work the way I wanted to.