Reputation:
<a href="test1.php" class="test">test1.php</a>
<a href="test2.php" class="test">test2.php</a>
<a href="test3.php" class="test">test3.php</a>
<a href="test4.php" class="test">test4.php</a>
...
<a href="testN.php" class="test">testN.php</a>
We can get attr a
one link:
$('.el').click(function(){
var href = $('.test').attr('href');
});
But how get array with all href all links?
Upvotes: 1
Views: 45
Reputation: 8954
var hrefArray = [];
$.each($('a'), function(index, element){
hrefArray.push(element.href);
});
Upvotes: 0
Reputation: 9637
Try to use .map()
along with .get()
to collect all of those href associated with relevant anchor tags in an array,
$('.el').click(function(){
var href = $('.test').map(function(){
return $(this).attr('href');
}).get();
});
Upvotes: 2