Govind Samrow
Govind Samrow

Reputation: 10179

How to get value of multiple files in array without any loop statement

Is it possible to get value of all elements return by find or children method without loop?

There is multiple li that contai hidden field and we want to get all these hidden field val.

i.e. var cats = $(this).next('ul').find('.hdn_id').val();

But its return only single value.

Upvotes: 4

Views: 197

Answers (2)

user5116395
user5116395

Reputation:

.contents()
.filter(function(){
return this.nodeType !== 1;
})

Upvotes: 0

Satpal
Satpal

Reputation: 133403

You need to iterate the elements, For simplicity .map() can be used.

Pass each element in the current matched set through a function, producing a new jQuery object containing the return values.

var cats = $(this).next('ul').find('.hdn_id').map(function () {
    return $(this).val();
}).get();

As the return value is a jQuery object, which contains an array, it's very common to call .get() on the result to work with a basic array.

Upvotes: 3

Related Questions