admin管理员组文章数量:1208155
In jQuery, it is easy to select elements as array.
$("a"); // return as elements array of anchors
But is it possible to select matched elements' attributes as array?
Currently I need to do something like...
links = [ ];
$("a").each(function() {
href = $(this).attr("href"); links.push(href);
});
Are there any better method to fill the variable links with href of the all matched anchors?
In jQuery, it is easy to select elements as array.
$("a"); // return as elements array of anchors
But is it possible to select matched elements' attributes as array?
Currently I need to do something like...
links = [ ];
$("a").each(function() {
href = $(this).attr("href"); links.push(href);
});
Are there any better method to fill the variable links with href of the all matched anchors?
Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked Jul 28, 2010 at 16:34 HowardHoward 19.8k36 gold badges115 silver badges187 bronze badges2 Answers
Reset to default 19Use $.map like so:
var links = $('a').map(function() { return this.href }).get()
var links = $("a").map(function(){return $(this).attr("href")}).get();
本文标签: javascriptReturn matched elements39 attribute ar array using jQueryStack Overflow
版权声明:本文标题:javascript - Return matched elements' attribute ar array using jQuery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738715744a2108466.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论