samedi 6 juin 2015

Jquery - Random element heights

here is my loop:

var i=0;
while( i++ < 100) {
  $( "#container" ).append('<li id="li' + i + '" class="item image"></li>');
  var y = Math.floor(Math.random() * 200) + 100;
  $('#li' + i).css({
      height: y,
  });
}

This somewhat does what I need it to do. It locates the #container element and puts 100 list items inside of it and gives them random heights no greater than 300.

What I really need it to do is 2 things:

  1. I need it to locate the "ul" #container element then locate the "li" elements that are already inside and change the ids to id="li1", id="li2", id="li3", etc possibly using attr('id', 'li' + i) and give them a random height.

  2. I need them to have an minimum height of 200px.

How can I do this with a loop? I'm still new to jquery so forgive my ignorance.




Aucun commentaire:

Enregistrer un commentaire