0

I have a block of code that I want to try and refactor.

    $(function () {
        $('.dots:nth-of-type(1)').click(function () {
            currentSlide(1);
        });
        $('.dots:nth-of-type(2)').click(function () {
            currentSlide(2);
        });
    });

How can I make the nth-of-type(1) dynamic along with the currentSlide(1) so that for each nth-of-type(), I just need to click on it in order currentSlide to be the same?

1 Answer 1

2

Use jQuery's index method:

$(function() {
    $('.dots').click(function() {
        currentSlide($(this).index());
    });
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.