Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select td which contains a (Anchor) tag using jquery

Tags:

html

jquery

I have an HTML code as given below. I want to select all td which contains a(anchor) as an immediate child (Here First TD tag) using jQuery.

<table>
  <tr>
    <td><a href="abc.aspx">ABC</a></td>
    <td>Second Level<span> >> </span>
        <div>
          <table>
             <tr>
               <td><a href="efg.aspx">EFG</a></td>
             </tr>
          </table>
        </div>
    </td>
 </tr>

like image 823
Dharmesh Avatar asked Dec 09 '22 00:12

Dharmesh


2 Answers

Description

Many ways to do this

You can use the parent css selector or jQuery's parent() function. Check out the sample and this jsFiddle Demonstration

Sample

  1. ​$("td > a").parent()
  2. $("td > a:parent")

More Information

  • jQuery - :parent Selector
  • jQuery - parent()
like image 54
dknaack Avatar answered Dec 31 '22 18:12

dknaack


This should do the trick:

$("td > a").parent();
like image 41
sp00m Avatar answered Dec 31 '22 19:12

sp00m