简体   繁体   English

不仅获得第一个而且获得所有匹配元素的 href ?

[英]Getting href of not only first but all matched elements?

With the code below I only get the href of the first matched element.使用下面的代码,我只能获得第一个匹配元素的href

$("a.item").attr("href")

How can I get the href of all matched elements?如何获取所有匹配元素的href

You can map it to get an array:您可以映射它以获取数组:

var hrefs = $("a.item").map(function(){
    return $(this).attr('href'); // or this.href (returning absolute path)
}).get();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM