简体   繁体   中英

Hide bootstrap carousel indicators when there is only one content

I've seen many examples in different languages but nothing with JavaScript/JQuery.

I currently build my Carousel in my JS from my XML file, where I declare img path etc. Now I have the issue that my Carousel contain just one image sometimes and if that's so, I want to hide my carousel-control and my carousel-indicators

How can I check in JS if there is more than one Image?

在此处输入图像描述

First, you should have a class attribute for the images in your carousel, then you use the getElementsByClassName to save the image into an array, and you will get all your images.

 let myImg = document.getElementsByClassName("your-image-in-carousel") console.log(myImg)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM