jess jess - 1 year ago 39
jQuery Question

how to initialize multiple instances of slider script - one slider for each div based on the div's class attribute

I'm pretty new to javascript. I'm having trouble initializing multiple instances of a slider script. I want 1 slider initialized for each div with class "horizontalSlider" by giving the script that div's id so that each instance is unique.

Here's what I have so far but it is not working.

$(document).ready(function(){
$('.horizontalSlider').each(function(){
var thisSlider = '"#' + $(this).attr("id") + ' ul"';
$(thisSlider).bxSlider({
mode : 'horizontal',
speed : 500,
prevImage : 'prev.svg',
nextImage : 'next.svg',
easing : 'swing'
});
});
});

Rab Rab
Answer Source
      $(document).ready(function(){
            $('.horizontalSlider').each(function(){

                $(this).bxSlider({
                    mode : 'horizontal',
                    speed : 500,
                    prevImage : 'prev.svg',
                    nextImage : 'next.svg',
                    easing : 'swing'
                });
            });
        });
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download