开发者

Select the ids from an array of jquery elements

开发者 https://www.devze.com 2023-01-27 15:03 出处:网络
With the following jquery statement I select an array of elements: selectedSupplierIds = $(\'.supplierListCheckbo开发者_运维问答x:checked\');

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

selectedSupplierIds = $('.supplierListCheckbo开发者_运维问答x: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?


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();
0

精彩评论

暂无评论...
验证码 换一张
取 消