Reputation: 71
I'm quite new to jQuery and ran into a problem I can't solve. I need to get a href that I want to select via a parant td with two classes. Important: There a several occurrences in the code from that class, I need to select the FIRST. Here is the HTML Code:
<td class="trackerList small>
<a href="index.php?moduleAccounts......."> (...) </a>
</td>
Here is my jQuery Selector (that obviously doesn't work - alert just for testing):
var a_href = jQuery('.trackerListBullet.small').first().child().attr('href');
alert (a_href);
Thanks a lot, tried for more than two hours now but can't find the right selecor...
Upvotes: 2
Views: 2508
Reputation: 18873
Try This :-
var a_href = jQuery('td.trackerList.small').find('a:first').attr('href');
alert (a_href);
Upvotes: 1
Reputation: 136074
$(function() {
var a_href = jQuery('td.trackerList.small:first a').attr('href');
alert(a_href);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td class="trackerList small">
<a href="index.php?moduleAccounts1"> (...) </a>
</td>
</tr>
<tr>
<td class="trackerList small">
<a href="index.php?moduleAccounts2"> (...) </a>
</td>
</tr>
</table>
Upvotes: 1