简体   繁体   中英

Getting href of not only first but all matched elements?

With the code below I only get the href of the first matched element.

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

How can I get the href of all matched elements?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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