samedi 27 décembre 2014

Add class to every few random elements with jquery

I have a sequence of elements, let's say:



<div class="tile1"></div>
<div class="tile2"></div>
<div class="tile3"></div>
<div class="tile4"></div>


etc.


How would I use Jquery to add the new class "color" to every few random elements with an increment varying between 2 and 6 like so:



<div class="tile1"></div>
<div class="tile2 color"></div>
<div class="tile3"></div>
<div class="tile4"></div>
<div class="tile5 color"></div>
<div class="tile6"></div>
<div class="tile7 color"></div>
<div class="tile8"></div>
<div class="tile9"></div>
<div class="tile10"></div>
<div class="tile11"></div>
<div class="tile12 color"></div>


etc.





Aucun commentaire:

Enregistrer un commentaire