获取href不仅是第一个,而且是所有匹配的元素

Getting href of not only first but all matched elements?

本文关键字:元素 href 第一个 获取      更新时间:2023-09-26

使用下面的代码,我只得到第一个匹配元素的href

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

如何得到所有匹配元素的href ?

你可以映射它来得到一个数组:

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