Reputation: 381
Hi I have extracted the html source code from a website using jquery. I am trying to extract link under a specific tag which is of the form <p class="title"> <a href="some link ">
I am trying to extract the link under a href.
To extract the html i did
$.get("link",function(data){ alert($data('p').attr('title')); }
data contains the html source code. The alert box shows as undefined. Is it not possible to extract the
tag with data in this format? I am not able to get how to extract the link under the href tag. Please help
Upvotes: 0
Views: 86
Reputation: 18155
Original Solution (finds first link)
$.get("link",function(data){ alert($(data).find('p.title a').attr('href')); }
Modified Solution (finds all links)
$.get("link", function(data) {
var links = [];
$(data).find('p.title a').each(function() {
links.push($(this).attr('href'));
});
alert(links.join(', '));
});
Upvotes: 3
Reputation: 645
From your example it looks like you should be doing this:
$.get("link",function(data){ alert($(data).find('p.title a').attr('href')); }
Upvotes: 1