$(document).ready(function() { var a = $('div.wrapper > a'); var wid = a.length; for( var i = 0; i < wid; i+=8 ) { a.slice(i, i+8).wrapAll('<div class="slide"></div>'); }; $(".pro").click(function() { $(".pro1").toggle('hide'); return false; }); });
.slide{ background: red; margin: 4px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <div class="wrapper"> <a href="#"><img src="#" /></a> <a href="#" class="pro1"><img src="#" /></a> <a href="#"><img src="#" /></a> <a href="#"><img src="#" /></a> <a href="#"><img src="#" /></a> <a href="#"><img src="#" /></a> <a href="#"><img src="#" /></a> <a href="#"><img src="#" /></a> <a href="#"><img src="#" /></a> <a href="#"><img src="#" /></a> <a href="#"><img src="#" /></a> <a href="#"><img src="#" /></a> <a href="#"><img src="#" /></a> </div> <a href="" class="pro">Клик</a>
There is such a code. It is necessary that when the button is pressed, length is recalculated and the 8th picture is added to the first block when it disappears from this block.
This is how it should work when you click
$('.wrapper a:visible').length
- Mr. Black