1

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'
                    });
                });
            });
jess
  • 15
  • 5

3 Answers3

2
      $(document).ready(function(){
            $('.horizontalSlider').each(function(){

                $(this).bxSlider({
                    mode : 'horizontal',
                    speed : 500,
                    prevImage : 'prev.svg',
                    nextImage : 'next.svg',
                    easing : 'swing'
                });
            });
        });
Raab
  • 34,778
  • 4
  • 50
  • 65
0

You can do it like this:

            $(document).ready(function(){
                $('.horizontalSlider').each(function($element){
                    $element.bxSlider({
                        mode : 'horizontal',
                        speed : 500,
                        prevImage : 'prev.svg',
                        nextImage : 'next.svg',
                        easing : 'swing'
                    });
                });
            });
0

I think that in this case it is not necessary the each

It could be simplified to the following:

$(document).ready(function(){
            $('.horizontalSlider').bxSlider({
                mode : 'horizontal',
                speed : 500,
                prevImage : 'prev.svg',
                nextImage : 'next.svg',
                easing : 'swing'
            });
        });