How to get and use a Swiper instance

Swiper is a very popular slider library that offers a versatile yet simple API. To access a specific instance of Swiper, you can get it in the following way

var mySwiper = document.querySelector('.swiper').swiper;.

Various methods of Swiper are available for instances of Swiper retrieved in this way. For example, to move to the next slide:

mySwiper.slideNext();.

Also, note that when referring to a Swiper instance in jQuery’s ” each" function, etc., use this.swiper instead of $(this).swiper.

This is because the Swiper instance is associated with the DOM element itself and must be accessed as a pure JavaScript object, not a jQuery object.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top