-2

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?

conan
  • 1,327
  • 1
  • 12
  • 27

4 Answers4

1

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
}

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators#Logical_AND_.28&&.29

Community
  • 1
  • 1
Musa
  • 96,336
  • 17
  • 118
  • 137
0

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.

Aborysa
  • 21
  • 4
0

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() {...

Robert
  • 10,126
  • 19
  • 78
  • 130
0

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, returns expr2. Thus, when used with Boolean values, && returns true if both operands are true; otherwise, returns false.

Community
  • 1
  • 1
Sumner Evans
  • 8,951
  • 5
  • 30
  • 47