Essentially, i have been unable to find a way to make the following .click() work more than once. My intent is to make is so that repeating clicks of the .gen2 class will continually .remove() the current .gen2 image and replace it with a randomly selected image from myArray.
$(document).ready(function(){
$('.gen2').click(function(){
$('.gen2').remove();
var myArray = ['<img class="gen2" src="images/bottom/chinchilla.png" />',
'<img class="gen2" src="images/bottom/bird.png" />',
'<img class="gen2" src="images/bottom/bluejay.png" />',
'<img class="gen2" src="images/bottom/walrus.png" />'];
var rand = myArray[Math.floor(Math.random() * myArray.length)];
$('.change').append(rand);
});
$('.gen1').click(function(){
$('.gen1').remove();
var array = ['<img class="gen1" src="images/top/raven.png" />',
'<img class="gen1" src="images/top/boar.png" />',
'<img class="gen1" src="images/top/trex.png" />'];
var rand = array[Math.floor(Math.random() * array.length)];
$('.change').append(rand);
});});
HTML is as follows. because the positions of both .gen1 and .gen2 are set to absolute, they overlap so that as each is removeed and proceedurally replaced with .append(), a new image is formed.
<body>
<div class="change">
<img class="gen1" src="images/top/raven.png" />
<img class="gen2" src="images/bottom/chinchilla.png" />
</div>
the problem is that after the first click(); the function no longer runs. I can't figure how..
Thanks!