davioooh
davioooh

Reputation: 24676

Get all selected items value

I need to get all values from a set of input text in my page and I need to know if someone of these inputs has value 'some value'

I'm using JQuery so I'm doing something like:

$('input.partValue').each(function(){
    int count = 0;
    if($(this).val() == 'some value'){
        count++;
    }
});
if(count > 0){
    // do something
}

but could be useful to have something like:

if($("input.partValue[value='some value']").length > 0){
    // do something
}

There is something similar?

Upvotes: 1

Views: 52

Answers (1)

VisioN
VisioN

Reputation: 145398

You can use filter():

var elems = $("input.partValue").filter(function() {
    return this.value == "some value";
});

if (elems.length > 0) { ... }

Upvotes: 3

Related Questions