views:

37245

answers:

5

Hey, I'm a little confused about a simple jQuery statement...

I want the operation to proceed only if A and B are true. If A isn't true, stop. If A and B are true, then continue.

Thanks!

A: 
if(A && B){ }
Doomspork
+13  A: 

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...

Rob
+2  A: 

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

$(document).ready(function() {
  if (someCondition && someOtherCondition) {
    // make some jQuery call
  }
});
Paul Morie
+2  A: 

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...
}
great_llama
As long as A() doesn't return false or null it will be true.
Schotime
+1  A: 

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;
}
ozke