Search code examples
javascriptjquerybxslider

How to disable next/prev button when slider have only one image?


When slider have one image then don't want next/prev button but if slider have more than 1 images then required next/prev button. Can you please suggest me JavaScript code to do. I know how to disable next/prev through controls false

controls : false

but it is also false when image have more than one image. Here is my code,

<script>
var imgCnt = $('#images div').val(); //get images count.
if(imgCnt == 1){
$('.bxslider').bxSlider({
controls:false
});
}else{
controls:true
}
</script>

Solution

  • I have tried this code and it's working fine. Please try to your program. Using ternary operator.

    $(document).ready(function(){
        $('ul.bxslider').bxSlider({
            controls: ($("#images div").length > 1) ? true: false,
        });
    });