Website under maintenance!

If Else Statement in JQuery

Posted on September 19, 2016 - Tags: ,

Like in other programming languages, JQuery uses the same format for for if else statement. Take a look at the simple format:


if(condition) {
//if condition is true, return something
// if condition is false, return something
}

Here is how to write this is in JQuery with CSS selectors:

if(temperature >= 80){
$("#msg").text("It will be hot in your area today.");
}else{
$("#msg").text("Stay warm. It is going to be cold today.");
}

In the above example, if the temperature is greater than 80 print “It will be hot in your area today.” into msg id tag. Else print “Stay warm. It is going to be cold today.” into the msg id tag.