Reputation: 5063
I have the following code
<tr id="myid">
<td>
<div>
...
<a href="" class="myclass"></a>
<a href="" class="myclass"></a>
<a href="" class="myclass"></a>
<a href="" class="myclass"></a>
<a href="" class="myclass"></a>
...
</div>
</td>
</tr>
<tr id="anotherid">
<td>
<div>
...
<a href="" class="myclass"></a>
<a href="" class="myclass"></a>
<a href="" class="myclass"></a>
<a href="" class="myclass"></a>
<a href="" class="myclass"></a>
...
</div>
</td>
</tr>
and I'm trying to select A tags inside tag TR with ID "myid" attribute however the following code doesn't works:
$('#myid.myclass')
How can I select the A tags, using the TR ID?
Upvotes: 3
Views: 6574
Reputation: 28076
Its the same with CSS selectors. Your mark up means that you will need a space:
Answer
$('#myid .myclass')
info
this $('#myid.myclass')
would mean that .myclass sits along side #myid
like this:
<tr id="anotherid" class="myclass">
Upvotes: 0
Reputation: 318252
To select all <a>
tags inside #myid
regardless of nesting
$("a", "#myid")
Upvotes: 1
Reputation: 66673
Use this: $('#myid .myclass')
- There should be a space between #myid
and .myclass
Upvotes: 7