I wanted to make a mini game where
5 balls go up from the bottom and when you click on one of them, it disappears, and a new one appears in the random position instead.
Created one item in html and cloned it 5 times . but when you click on one of the clones, only the last of them disappears, and so in order.
How to fix it?
And in general, how to make the element appear again in a random place ??
$(function() { function getRandomInt(min, max) { return Math.round(Math.random() * (max - min + 1)) + min; } var e = $('.el'); for (var i = 0; i < 5; i++) { e.clone().insertAfter(e); } var score = 0; $('.el').click(function() { $('.el').each(function() { $(this).css({ 'transform': 'translateY(-600px)', 'transition': getRandomInt(5000, 10000) + 'ms' }); }) $(this).addClass('display'); score++ $('.score span').text(score); }) }); .el { background-color: red; width: 50px; height: 50px; border-radius: 50%; display: inline-block; margin-left: 5px; } .display { display: none } .army { position: absolute; bottom: 0; } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="score"> <h2>your score: <span></span></h2> </div> <div class="army"> <div class="el"></div> </div>