user3861559 user3861559 - 1 year ago 70
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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download