Skip to content Skip to sidebar Skip to footer

Jquery If Statement, Syntax

What is a simple jQuery statement that states an operation proceeds only if A and B are true? If A isn't true, stop. If A and B are true, then continue. `

Solution 1:

jQuery is just a library which enhances the capabilities of the DOM within a web browser; the underlying language is JavaScript, which has, as you might hope to expect from a programming language, the ability to perform conditional logic, i.e.

if( condition ) {
    // do something
}

Testing two conditions is straightforward, too:

if( A && B ) {
    // do something
}

Dear God, I hope this isn't a troll...

Solution 2:

You can wrap jQuery calls inside normal JavaScript code. So, for example:

$(document).ready(function() {
    if (someCondition && someOtherCondition) {
        // Make some jQuery call.
    }
});

Solution 3:

To add to what the others are saying, A and B can be function calls as well that return boolean values. If A returns false then B would never be called.

if (A() && B()) {
    // if A() returns false then B() is never called...
}

Solution 4:

It depends on what you mean by stop. If it's in a function that can return void then:

if(a && b) {
    //do something
}else{
    //"stop"return;
}

Solution 5:

if(A && B){ }

Post a Comment for "Jquery If Statement, Syntax"