if else on click jquery code example

Example 1: jquery if else on click

$('#myElementID').click(function() {
	var isSomethingTrue = true;
    
    if(isSomethingTrue){
    	alert("something is true");
    }else{
    	alert("something is false");
    }
});

Example 2: if else jquery click function

if(jQuery('#id').click) {
    //do-some-stuff
} else {
    //run function2
}

Example 3: jquery if else click function

$(document).ready(function(){ 

	var n = $("#example div").length;

	if (n < 2) {
		$("body").css("background", "green");
	} 
	else {
		$("body").css("background", "orange");
	}

});