Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 244
Kevin Brown Avatar asked May 20 '09 01:05

Kevin Brown


People also ask

Can you use if statement in jQuery?

The conditional loops that can be worked in a jQuery script are 'if' statement, 'if..else' statement, and 'if..else if' statement. Each of these statements can operate based on their traditional principles, along with the commonly used relational operators like <, >, =, <=, >=, !=

What is the syntax of if else statement?

Syntax. If the Boolean expression evaluates to true, then the if block will be executed, otherwise, the else block will be executed. C programming language assumes any non-zero and non-null values as true, and if it is either zero or null, then it is assumed as false value.

How call jQuery function in if condition?

getElementById("title"). value; var flagu2=0; ..... ..... var flagu6=0; if( flagu1==0 && flagu2==0 && flagu3==0 && flagu4==0 && flagu6==0 ) return true; else return false; } function clearBox(type) { // Your implementation here } // Event handler $submitButton. on('click', handleSubmit); });

How do you write an if statement?

An if statement is written with the if keyword, followed by a condition in parentheses, with the code to be executed in between curly brackets. In short, it can be written as if () {} .


3 Answers

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

like image 176
Rob Avatar answered Sep 21 '22 21:09

Rob


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

$(document).ready(function() {
    if (someCondition && someOtherCondition) {
        // Make some jQuery call.
    }
});
like image 31
Paul Morie Avatar answered Sep 21 '22 21:09

Paul Morie


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...
}
like image 23
great_llama Avatar answered Sep 23 '22 21:09

great_llama