Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select the ids from an array of jquery elements

Tags:

arrays

jquery

With the following jquery statement I select an array of elements:

selectedSupplierIds = $('.supplierListCheckbox:checked');

I need to select the ids from these elements. Can I do this without creating an array and pushing the ids in a for loop?

like image 653
Boris Callens Avatar asked Dec 13 '25 22:12

Boris Callens


1 Answers

You can use .map() to get an array of anything based on your object selection...in this case your just want the .id property from each, like this:

var arr = $('.supplierListCheckbox:checked').map(function() { 
            return this.id; 
          }).get();
like image 148
Nick Craver Avatar answered Dec 16 '25 12:12

Nick Craver



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!