2

The title sounds confusing.. but im sure this is possible!

I have one button, (id='downloadAll') and many <a href="..." class="link"></a> on my page. What i want to do, for the purpose of finding out how to do this.. is to do something logic like this.

var hrefs = ALL OF THE ELEMENTS WITH CLASS 'link';
foreach(hrefs){
 alert(this.attr('href'));
}

Basically for each of the elements with a class, i want to get the value of each one... in tern. Yes, i do have jquery on the page - am hoping to make use of this!

Thanks!

2 Answers 2

14
$("a.link").each(function() {
  alert($(this).attr("href"));
});
Sign up to request clarification or add additional context in comments.

1 Comment

Ah! haha thanks! i found that literally 2 seconds before you posted ;) thanks!!
0

You should write something like this:

$.each(hrefs, function(){
  alert(this.href);
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.