Get the attribute value of each element from a jQuery set, into an array

前端 未结 4 1210
Happy的楠姐
Happy的楠姐 2021-02-08 02:25

How can I get all attributes (e.g. href) of all elements matching a jQuery selector?

4条回答
  •  醉话见心
    2021-02-08 03:16

    Something like this perhaps?

    var ids = [];
    
    $('.myClass').each(function () {
      ids.push($(this).attr('id')); // ids.push(this.id) would work as well.
    });
    

提交回复
热议问题