count all elements with class jquery
var numItems = $('.item').length;
Here is what the above code is Doing:
1. We’re creating a variable called numItems and setting it equal to the number of items in the carousel.
2. We’re creating a variable called totalItemsWidth and setting it equal to the width of the carousel multiplied by the number of items in the carousel.
3. We’re creating a variable called totalWidth and setting it equal to the width of the carousel multiplied by the number of items in the carousel plus the width of the carousel.
4. We’re creating a variable called numItems and setting it equal to the number of items in the carousel.