Can you please let me know how I can get the total and current number of the carousel slides in bootstrap like the image below?
I have an standard Bootstrap carousel and a <div>
with the .num
class to display the total and current number and I used this code to retrieve the numbers but it didn't go through
$('.num').html(){
$('#myCarousel').carousel({number})
}
Thanks
Update:
Please find a sample at this jsfiddle LINK
Each
slide
has a.item
class to it, you can get the total number of slides like thisActive
slide
has a class named asactive
, you can get the index ofactive slide
like thisYou can update these values by binding the bootstrap carousel
slid
event like thisEXAMPLE
Update of @Khawer Zeshan's code
For Bootstrap 3.0+ use
slid.bs.carousel
instead ofslid
andon
instead ofbind
. So the update code will be like thatThe only drawback with the below code will be that it doesn't show up till you go to next slide (triggers after each slide change).
JS/jQuery
HTML
Bootstrap 3.2+:
You can use jquery index() function to get the current index of active element inside list of item. So the code is look like this:
after slide event div will be active and can not get active index, so keep you code inside set time out function