[SOLVED] Recover data from virtual swiper on "slideChange"

I created a virtual swiper where their slides have data, I want to get “data-titulo”:

      getCuentosSlides: function(libros){
        let cuentosSlides = [];
        for (var i = 1; i <= libros.length; i++) {
        const libro = libros[i];
        cuentosSlides.push('<div data-titulo=' + libro + ' class="swiper-slide"><img src="static/' + i +'.jpg" width="100%"></div>');
        return cuentosSlides;

 var cuentosSwiper = new Swiper('.cuentos-swiper-container', {
          virtual: {
            slides: this.getCuentosSlides(libros)

cuentosSwiper.on('slideChange', function () {        
    console.log("how to get data-titulo");


I found a not optimal way:
using cuentosSwiper.activeIndex I can get the position and then search in another array the data with this index.

If there is a way to go directly to “data-titulo” it would be better. I tried to get it from cuentosSwiper.$el but I did not get it

cuentosSwiper.on('slideChange', function () {   
    var swiper = this;
    var slide = swiper.slides.eq(swiper.activeIndex);
    var id =  slide.attr('data-titulo');
1 Like

like always, work perfectly. thanks! @nolimits4web