jQuery randomly add class to list items with limit -


i have bit fo code working fine, either doesn't add class or ads classe of wide items within list.

i trying find solution limit how many of list items can have class of wide.

i using more masonry wall , limit number of wide items within wall.

my current code below, there way limit this?

// random masonry item class on homepage jquery(document).ready(function(){     var classes = [" ", "wide"];      jquery(".mix-target").each(function(){         jquery(this).addclass(classes[~~(math.random()*classes.length)]);     }); }); 

something this?

jquery(document).ready(function(){     var classes = [" ", "wide"];      var limit = 3;     jquery(".mix-target").each(function(){         if (limit == 0)             return false;          var index = ~~(math.random()*classes.length);         if (index == 1)              limit--;          jquery(this).addclass(classes[index]);     }); }); 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -