Making div element dynamic with another function

27
October 17, 2019, at 09:30 AM

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?

Answer 1

Use jQuery's index method:

$(function() {
    $('.dots').click(function() {
        currentSlide($(this).index());
    });
});
READ ALSO
resize svg wrapped in div that is wrapped in div

resize svg wrapped in div that is wrapped in div

I'm having a problem coverting inline SVG to be wrapped in divsI was using nested SVGs before and now I'm told I have to use nested divs with inline SVG

6
responsive grid of different sized images with real world proportions and scale

responsive grid of different sized images with real world proportions and scale

I have a laravel site that loads product images into a grid-container--fit row through a @foreach loopThe images are all sorts of different sizes, some are portrait and some are landscape

15
How to include jar files with java file and compile in command prompt

How to include jar files with java file and compile in command prompt

I have 3 jar files and ajava file that depends on these jar files

57