Getting the attribute of a parent
<p>I'm trying to get the id of a table using a table row. While I am in a loop:</p>

<pre><code>$(this).parent.attr('id');
</code></pre>

<p>However I am getting an error. Is my syntax right?</p>

<p>Thanks.</p>

<p>EDIT:</p>

<pre><code>&lt;table id="21-rawTable" border="1"&gt;&lt;tbody&gt;&lt;tr class="even notSelected eClr" name="0" id="beaf-32;Developmental-Stage_Embryo-0-12h;ChIP-chip;Rep-1;input;Dmel_r54;modENCODE_21;BEAF_Input_0.CEL" title="/modencode/modencode-dcc/symbolic_links/Dmel_r5.4/Non-TF-Chromatin-binding-factor/ChIP-chip/raw-arrayfile_CEL/beaf-32/Embryo 0-12h/" style="cursor:pointer;" "="" onclick="selected('beaf-32;Developmental-Stage_Embryo-0-12h;ChIP-chip;Rep-1;input;Dmel_r54;modENCODE_21;BEAF_Input_0.CEL','[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]')"&gt;&lt;td class="checkbox"&gt;&lt;input type="checkbox" id="beaf-32;Developmental-Stage_Embryo-0-12h;ChIP-chip;Rep-1;input;Dmel_r54;modENCODE_21;BEAF_Input_0.CELcheckBox" checked=""&gt;&lt;/td&gt;&lt;td&gt;beaf-32;Developmental-Stage_Embryo-0-12h;ChIP-chip;Rep-1;input;Dmel_r54;modENCODE_21;BEAF_Input_0.CEL&lt;/td&gt;&lt;td&gt;0 bytes&lt;/td&gt;&lt;/tr&gt;&lt;!-- table--&gt;&lt;/tbody&gt;&lt;/table&gt;
</code></pre>

<p>Using this code to get the id of the table which in this case is "21-rawTable"</p>

<pre><code>$(".selected").each(function () {
var parentname = $(this).parent().attr('id');
        alert (parentname);
});
</code></pre>

<p>I resolved the issue. I think it was giving me the direct parent. Instead I had to do a search for the closest ancestor like such:</p>

<pre><code>var parentname = ($(this).closest('table')).attr('id');
</code></pre>

<p>Thanks.</p>
