I don't want to ask this stupid question, but I have searched all over the stackoverflow and google, it seems jquery has no one ever talk about 'and' function in jquery. I use && in php, but what should I use for jquery?
-
3You could simply just have tried if `&&` worked in jQuery, which it does. – Cyclonecode Feb 15 '15 at 22:43
-
3`&&` is actually JavaScript, not jQuery. – Alexander O'Mara Feb 15 '15 at 22:43
-
http://stackoverflow.com/questions/10261150/jquery-javascript-and-the-use-of-operators – Cyclonecode Feb 15 '15 at 22:44
-
1I'd suggest you read this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators – jfriend00 Feb 15 '15 at 22:45
4 Answers
The logical and operator in php is &&
and and
, they are not exactly the same though.
See PHP : Difference between '&&' and 'AND'
If you want to use the logical and operator in JavaScript (using jQuery) it is &&
if ($('#all').is(':visible') && $('#none').is(':visible')){
// We have a problem
}
jQuery isn't a language, but a plugin for javascript. You would use && in javascript as "and" operator just as you would do in php.

- 21
- 4
-
Do you have an example of some other description of the `&&` statement? – Sumner Evans Feb 15 '15 at 22:49
If I understand your question correctly you want to use the &&
logical operator in jQuery?
jQuery is a JavaScript library so you can use &&
. Here is the documentation from JavaScript.
If you are trying to select multiple elements I suggest you use the following:
$("element1, element2").click(function() {...

- 10,126
- 19
- 78
- 130
MDN has an article outlining Logical Operators in JavaScript. It states:
Operator: Logical AND (
&&
)
Usage:
expr1
&&expr2
Description: Returns
expr1
if it can be converted to false; otherwise, returnsexpr2
. Thus, when used with Boolean values,&&
returnstrue
if both operands aretrue
; otherwise, returnsfalse
.

- 1
- 1

- 8,951
- 5
- 30
- 47