dimanche 5 avril 2015

jquery if else doesnt give back an alert message

everything is writen in an external javascript file what I included in the html I also have the jquery link in there.


I tried to change put the if statment on diffrent positions in the code, I looked arround if the width was incorrect and some other things whitch are inrelevent at the moment.


When I changed the $foodcheck).width > '0px' to a < and the else if to a > the alert did work but ofc I only want it to pop up if the width = 0


I want it to give back the alert message.



var $foodcheck = $('#greenfood');
if(($foodcheck).width > '0px') {

document.getElementById("f").onclick = function(){

var random = Math.random();

if(random > 0.0 && random <= 0.5) {

$("#greenfood").animate({width: "-=30px"});

} else if(random > 0.9) {

$("#greenfood").animate({width: "-=80px"});

} else {

$("#greenfood").animate({width: "140px"});

}
};
} else if(($foodcheck).width =< '0px'){
alert("Works");
}

Aucun commentaire:

Enregistrer un commentaire