L
L
LittleFatNinja2015-07-24 01:07:14
PHP
LittleFatNinja, 2015-07-24 01:07:14

How to filter when elements are in different blocks?

help me make such a filtering, I've been racking my brain all day, I can't figure out how to do this at all,
there is, let's say, this markup:

<ul>
   <li></li>
   <li class="hidden"></li>
   <li class="hidden"></li>
   <li></li>
</ul>
<ul>
   <li></li>
   <li></li>
   <li class="hidden"></li>
   <li></li>
</ul>

in the end it should turn out something like this:
<ul>
   <li></li>
   <li class="hidden"></li>
   <li class="hidden"></li>
   <li></li>
   <li></li>
   <li></li>
</ul>
<ul>
   <li class="hidden"></li>
   <li></li>
</ul>

that is, in the block there should be 4 visible elements
, is it possible to implement this at all?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
magazovski, 2015-07-24
@LittleFatNinja

var lis = $('li').filter(':not(hidden)');
var uls = $('ul');

for (var i=0; i < lis.length; i++) {
    $(lis[i]).appendTo(uls[~~(i/4)]);
}

Can be tweaked, but generally works as it should.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question