Onclick show next divs

前端 未结 3 902
無奈伤痛
無奈伤痛 2021-01-29 08:49

I have 1000 divs and 20 of them are visible and remaining are hidden.

In the onClick jquery event, I want the next 20 divs to become visible and so on.

3条回答
  •  生来不讨喜
    2021-01-29 09:46

    If you're using jquery, you can use the .slice() method.

    http://api.jquery.com/slice/

    Something like:

    $('button').click(function(e){
      var divs = $('.mydivs');
      divs.hide().slice(0, 20).show(); // 0 is the starting index
    });
    

    You'd just need to figure out the logic to determine what your starting index is.

    I don't have a non-jquery solution, maybe someone else could help on that front.

提交回复
热议问题