I want to make multiple divs appear in a defined time and when I click it, gives 300 Points (value), it starts with a value of 0 (punctuation) and triggers a function when the page is ready
var puntuacion = 0;
$(document).ready(function() {
FadeDiv();
function FadeDiv() {
var posx = Math.floor(Math.random() * 300);
var posy = Math.floor(Math.random() * 300);
$newdiv = $("<div id='circle-green'></div>").css({
'left': posx + 'px',
'top': posy + 'px'
});
$newdiv.appendTo('body').fadeIn(1000).delay(1000).fadeOut(1000, function() {
FadeDiv();
});
}
$("#Points").text(puntuacion);
$("#circle-green").click(function() {
$(this).remove();
puntuacion+=300;
$("#Points").text(puntuacion);
});
setTimeout(FadeDiv, 1000);
setTimeout(FadeDiv, 500);
setTimeout(FadeDiv, 100);
});
body {
background-color: #000;
color: #FFF;
font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 14px;
}
#circle-green {
width: 50px;
height: 50px;
position: absolute;
display: none;
background-color: #00ff00;
-webkit-border-radius: 25px;
-moz-border-radius: 25px;
border-radius: 25px;
cursor: pointer;
box-shadow: 1px 1px 5px 5px #00ff00;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<div id="Points"></div>
https://jsfiddle.net/k6shp80d/
but I can just click the first div, why? maybe because I'm new on JavaScript and jQuery, ask me any question or any doubt you have!, sorry for my bad english.
puntuacion = +300instead ofpuntuacion += 300IDon your html unique and I guess that's not happening.