Shantanu Paul
Shantanu Paul

Reputation: 705

phpquery: Extracting all hyperlinks with same class id?

Please help me to construct a jquery (phpquery) to parse the below sample to extract all the url's with the class "myblue". I am trying to make an app that displays the data from those url's.

  <table width="100%" cellspacing="1" cellpadding="2" border="0">
<tbody>
<tr>
<td class="inputtxt" height="20" bgcolor="#E4E4E4" colspan="2">
<b>Notices</b>
</td>
</tr>
<tr valign="top">
<td class="inputtxt" width="7%" valign="top" align="center">»</td>
<td width="93%" valign="top">
<a class="myblue" target="_blank" href="http://example.comn/"> Some Text</a>
</td>
</tr>
</tbody>
</table>
<table width="100%" cellspacing="1" cellpadding="2" border="0">
<tbody>
<tr>
<td class="inputtxt" height="20" bgcolor="#E4E4E4" colspan="2">
<b>Info</b>
</td>
</tr>
<tr valign="top">
<td class="inputtxt" width="7%" valign="top" align="center">»</td>
<td width="93%" valign="top">
<a class="myblue" target="_blank" href="xxxx.html"> Some Text</a>
</td>
</tr>

Upvotes: 0

Views: 79

Answers (2)

Jay Blanchard
Jay Blanchard

Reputation: 34426

If you need to extract them all you can loop through like this -

$('a.myblue').each(function() {
    console.log( $(this).attr('href') );
});

Upvotes: 0

T J
T J

Reputation: 43166

var urls=[];
$('a.myblue').each(function(){
 urls.push($(this).attr('href'));
})

or

var urls = $('a.myblue').map(function () {
 return $(this).attr('href');
})

Upvotes: 2

Related Questions