A
A
Alexander Rybakov2019-03-07 00:38:12
JavaScript
Alexander Rybakov, 2019-03-07 00:38:12

Why doesn't the attribute value change?

This code always outputs 0 even though the slides are switched and the "slick-current" class is reassigned to other slides?
There are five slides and the data attributes go from 0 to 4.

$('.content-inn').on('afterChange', function(){
    console.log($(".slick-active").attr('data-slick-index'));
})

I want it to give me the actual data-slick-index after each flip

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Proskurin, 2019-03-07
@turkish777

You don't need to go into the attributes, the afterChanges event already has the index of the current slide in its arguments

$('.content-inn').on('afterChange', function(event, slick, currentSlide){
     console.warn(currentSlide);  
});

D
DanKud, 2019-03-07
@DanKud

So you probably need to take an attribute from the current slide with the class .slick-current:

$('.content-inn').on('afterChange', function(){
    console.log($(".slick-current").attr('data-slick-index'));
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question