Reputation: 24
HTML Source Code:
<a href="http://asd.com/123/qwe">1</a>
<a href="http://asd.net/asd">2</a>
<a href="http://123.com">3</a>
<a href="http://www.a1s2d3.com">4</a>
<a href="http://www.q1w2e3.com">5</a>
<a href="http://bnm.org/questions/">6</a><br /><br />
<span id="element"></span>
jQuery Code
var total = $('a').size();
$('#element').text(total);
I get the size of a tags. But I cant get the href value of all a tags. How can I write the the loop?
Upvotes: 0
Views: 33
Reputation: 59252
You just need this:
$('#element').text(function(){
return $('a').map(function(){ return this.href }).get().join(",");
});
Basically
var arrOfLinks = $('a').map(function(){ return this.href }).get();
will give you array of links.
Upvotes: 1