jd says jd says - 7 months ago 29
Javascript Question

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').val(); //get images count.
if(imgCnt == 1){
$('.bxslider').bxSlider({
controls:false
});
}else{
controls:true
}
</script>

Answer

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: ($("ul.bxslider").length > 1) ? true: false,
    });
});