Reputation: 10179
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
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