How to get the value of multiple files in an array without a loop statement

Is it possible to get the value of all elements returned by find or children without a loop?

There are several li that hide the hidden field, and we want to get all these hidden val fields.

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

But it returns only one value.

+4
source share
2 answers

You need to iterate over the elements for simplicity . map () can be used.

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

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

jQuery, , .get() .

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

Source: https://habr.com/ru/post/1651364/


All Articles