I am getting familiar with jQuery and making a little application where a red box moves around the screen and the user has to try and click on it and when the user does an alert()
box pops up but the problem is that the alert()
keeps popping up even after 'ok' is pressed. The only way I can stop it is to repeatedly click 'ok' and eventually it goes away.
Here is the code that displays the alert box:
function Animate() {
var _newPosition = GetNewPosition();
// Sets new position of div
div.animate({
top: _newPosition[0],
left: _newPosition[1]
}, function () {
div.on('click', function () {
alert('You clicked the box!');
});
Animate();
});
}
Here is my JSFiddle that reproduces the problem
I originally thought that I could solve it by returning false
after the call to the alert()
for example:
div.on('click', function () {
alert('You clicked the box!');
return false;
});
But that didn't work either.
I know this should be a simple thing to figure out but I cant quite seem to get my thumb on it.