I have an if statement that should pop up an alert window if the condition is true, nut nothing happens.
Its like its not getting the value of the variable and yet the variable is being displayed in a div called result.
JS :
$x = 0;
$(window).load(function () {
$(".DragItem").draggable({
revert: 'invalid',
helper: "clone"
});
$(".drop1").droppable({
accept: '#1',
activeClass: 'DropTargetValid',
drop: function (ev, ui) {
var id = $(ui.draggable).attr("id");
$(ev.target).append(ui.draggable.clone());
$("#" + id).draggable('disable');
$x++;
document.getElementById("result").innerHTML = $x;
}
});
$(".drop2").droppable({
accept: '#2',
activeClass: 'DropTargetValid',
drop: function (ev, ui) {
var id = $(ui.draggable).attr("id");
$(ev.target).append(ui.draggable.clone());
$("#" + id).draggable('disable');
$x++;
document.getElementById("result").innerHTML = $x;
}
});
$(".drop3").droppable({
accept: '#3',
activeClass: 'DropTargetValid',
drop: function (ev, ui) {
var id = $(ui.draggable).attr("id");
$(ev.target).append(ui.draggable.clone());
$("#" + id).draggable('disable');
$x++;
document.getElementById("result").innerHTML = $x;
}
});
$(".drop4").droppable({
accept: '.DragItem',
activeClass: 'DropTargetValid',
drop: function (ev, ui) {
var id = $(ui.draggable).attr("id");
$(ev.target).append(ui.draggable.clone());
$("#" + id).draggable('disable');
}
});
});
if ($x == 3) {
// code to be executed if condition is true
alert('Well Done');
} else {
// code to be executed if condition is false
}
ifclause is outside your(window).loadit is actually executed before it, when your variable's value is still 0