Jquery: Extracting the hrefs from multiple links on a page.

Posted by Pete B on Stack Overflow See other posts from Stack Overflow or by Pete B
Published on 2010-04-01T23:36:24Z Indexed on 2010/04/01 23:43 UTC
Read the original article Hit count: 276

Filed under:

Hi,

I discovered that .attr() only applies to the first matched element on the page! So, I've been trying to get the hrefs from all the matched elements on a page, but to no avail.

Here's what I tentatively wrote:

    var thelinks = $("td a").each(function(){
    $(this).attr("href");
    document.write(thelinks);
});

I used document.write just to see what was going on, and I got a long list of "undefinedundefinedundefined"

What I'm trying to do is extract the hrefs from each td a and then use ajax to visit those pages and do other stuff. I can get it work fine when it's dealing with just one link, but this multiple elements thing I can't figure out.

Any help rendered is appreciated, I'm a novice to the world of Javascript and Jquery.

© Stack Overflow or respective owner

Related posts about jQuery