user702208
user702208

Reputation:

selectors in jquery

I want to select a link which is inside table tr td

<table>
    <tr>
        <td><a href=""></a></td>
    </tr>
</table>

This is my selector, but it is not working:

$(table#id tr>td>a.linkid);

Upvotes: 0

Views: 63

Answers (3)

Karoline Brynildsen
Karoline Brynildsen

Reputation: 3648

If you have an id on the link you can just write $('#linkID');

Or you can try jQuery find(): http://api.jquery.com/find/

Upvotes: 0

JohnP
JohnP

Reputation: 50009

Here's a demo : http://jsfiddle.net/jomanlk/bncas/

<table>
 <thead>
   <tr>
     <th>Title </th>
     <th>Title 2</th>
   </tr>
 </thead>
 <tbody>
   <tr>
     <td><a href='http://somesite.com'></a></td>
     <td><a class='linkid' href='http://correctsite.com'></a></td>
   </tr>
 </tbody>
</table>

$('td a.linkid').each(function(){
   $(this);// reference to link
});

$('td a.linkid:first'); //reference to first link

Upvotes: 1

Tim
Tim

Reputation: 9489

Try:

$("table#id > a.linkid");

See jQuery child selector here

Upvotes: 0

Related Questions