In JQuery, I don't quite understand this syntax. Can someone please elaborate

I understand everything that follows with the exception of “’ + next + '”

I understand that the + symbol is used as an operator or to concatenate, I am not sure how it’s being used here.

    var numberOfPics = $(this).find('div > img').length;
    var next = Math.floor(Math.random() * numberOfPics);
        '#pic_scroller>img:eq(' + next + ')', {duration: 1000}

Hi Crisrod,

The variable next is going to be a random integer representing the index of the next image to be scrolled to. That variable is then concatenated with another string to create a selector, used by the scrollTo function to select the relevant img element in the page. If next is 5, you’ll end up with the selector ‘#pic_scroller>img:eq(5)’.

So the “+” sign is used as a concatenation. Got it. Now that I look at it, I see it. Thank you so much. This is exactly the explanation I was looking for.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.