user3861559 user3861559 - 4 months ago 12
Javascript Question

More than one selector in Jquery if statement

I have 2 statements like this:

if ($('#lcheckbox').prop('checked')) {


if($("input[type='hidden'][name='optin']").length) {

Since what happens in the if condition is the same, I am wondering it there is way combine them into one. I tried Or operator, multiple selector trick but no avail. Any tips?


You can use the Or operator "||" to combine the two conditions :

if ( $('#lcheckbox').prop('checked') || $("input[type='hidden'][name='optin']").length) {
// your code

That's work on the exemple