henry
henry

Reputation: 119

Do something if one of the selected jQuery elements satisfy a condition

Is there a way to easily write a condition that result in true whenever one of the selected jQuery element satisfy a certain condition?

if($('input[name*="box_feature"]').attr('value') === undefined)) {

}

I have the above code, but the problem is that sometime we have more than one input with the same name and one of them can be defined. So what's the easiest way to do this in jQuery, that is, checking if at least one of the selected element meet a certain condition.

Upvotes: 0

Views: 198

Answers (1)

Alon Eitan
Alon Eitan

Reputation: 12025

You can check multiple attributes in the selector:

if( $('input[name*="box_feature"][value]').length > 0 ) {
    alert('found');
}

References:

Upvotes: 2

Related Questions