title: How to get table Id by .closest()?
body: <p>Based on the example below, I would like to retrieve the id of the parent table. Why is there no problem with DIV Id ?</p>
  <p>In console, I get undefined for the two first logs.</p>
  <pre><code>&lt;!DOCTYPE html&gt;
      &lt;html&gt;
      &lt;head&gt;
      &lt;script src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js&quot;&gt;&lt;/script&gt;
      &lt;script&gt;
  $(document).ready(function(){
  
    var f = $(&quot;span&quot;).closest(&quot;table.outherTabClass&quot;).attr(&quot;id&quot;);
    console.log(f);
    var g = $(&quot;span&quot;).closest(&quot;table.innerTabClass&quot;).attr(&quot;id&quot;);
    console.log(g);
    var h = $(&quot;span&quot;).closest(&quot;.firstLevelDivClass&quot;).attr(&quot;id&quot;);
    console.log(h);
    var i = $(&quot;span&quot;).closest(&quot;div&quot;).attr(&quot;id&quot;);
    console.log(i);
  
  });
      &lt;/script&gt;
      &lt;/head&gt;
      
      &lt;body&gt;
      &lt;div id=&quot;firstLevelDivId&quot; class=&quot;firstLevelDivClass&quot;&gt;
      &lt;table id = &quot;outherTabId&quot; class =&quot;outherTabClass&quot;&gt;
        &lt;table id = &quot;innerTabId&quot; class =&quot;innerTabClass&quot;&gt;
          &lt;div id =&quot;secondLevelDivId&quot;&gt;
              &lt;div id =&quot;thirdLevelDivId&quot;&gt;
                &lt;span&gt;spanText&lt;/span&gt;
             &lt;/div&gt;
          &lt;/div&gt;
        &lt;/table&gt;
        &lt;/table&gt;
        &lt;/div&gt;
      &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>