onClick cycle through DIVs with same class

前端 未结 1 1247
我在风中等你
我在风中等你 2021-01-20 20:56

I\'m trying to create a script to cycle through DIVs (one at a time) that have the same class name. .nextAll() and all that fun stuff is completely foreign to m

相关标签:
1条回答
  • 2021-01-20 21:21

    Here is a way to do it:

    (function(){
    
        var $hints = $('.hint');
        var $hintDescriptions = $('.hint-description');
        var i = 0;
    
        $('.next-hint').on('click', function(){
            i = (i + 1) % $hints.length;
            $hints.hide().eq(i).show();
            $hintDescriptions.hide().eq(i).show();
        });
    
    })();
    

    Updated JSFiddle

    0 讨论(0)
提交回复
热议问题