mardi 24 janvier 2017

How to randomly pick images and goes it to another empty list?

I have an unordered list of images with different colors and I want it to randomly pick a 2 images and goes to another list, I know the appendTo and Math.Random will do the trick but I dont know how to implement it can you help me?

Here's the fiddle and code

        <div class="row">
          <div class="col-md-6">
            <ul class="imageList">
              <li><img class="swapimage"  src="http://ift.tt/2jceIkZ" alt=""></li>
              <li><img class="swapimage"  src="http://ift.tt/2k0OcQ9" alt=""></li>
              <li><img class="swapimage" src="http://ift.tt/2jc01OO" alt=""></li>
              <li><img class="swapimage" src="http://ift.tt/2k0xVum" alt=""></li>
            </ul>
          </div>

          <div class="col-md-6">
            <ul class="randomList">
                <li></li>
                <li></li>
                <li></li>
                <li></li>
              </ul>
          </div>
        </div>
        <input class="main-button" type="button" value="swap" id="swapBtn" name="swapBtn">


$('#swapBtn').on('click', function(){
    $('.swapimage').prependTo('.randomList li');
});

http://ift.tt/2jc2Z64




Aucun commentaire:

Enregistrer un commentaire