Max
Max

Reputation: 5063

in jQuery, how to select by class child elements inside a tag with id attribute?

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

Answers (3)

Jamie Hutber
Jamie Hutber

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

adeneo
adeneo

Reputation: 318252

To select all <a> tags inside #myid regardless of nesting

$("a", "#myid")

Upvotes: 1

techfoobar
techfoobar

Reputation: 66673

Use this: $('#myid .myclass') - There should be a space between #myid and .myclass

Upvotes: 7

Related Questions