title: Can't get the element id on an onChange event in JavaScript via JQuery
body: <p>I have this small HTML page which exposes my problem. I want to get the id of the first ancestor of my input element (<code>#input-1</code>). When the user changes the option value, the JavaScript code should get the id of the <code>#li-1</code> element and display it. Unfortunately all I get is a <code>undefined</code> and I don't know why.</p>
  
  <p>The <code>parents()</code> function should traverse up the DOM tree and find the <code>li</code>  element, then get the id via the <code>.attr()</code> function</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$("#input-1").on("change", function(elem) {
    var id = $(elem).parents("li").attr("id");
    alert(id);
  })</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;html&gt;
  &lt;head&gt;
    &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  
    &lt;li id="li-1"&gt;
      &lt;div class="item-content item-input"&gt;
        &lt;div class="item-inner"&gt;
          &lt;div class="item-title item-label"&gt;Test&lt;/div&gt;
          &lt;div class="item-input-wrap"&gt;
            &lt;select id="input-1"&gt;
              &lt;option value="0"&gt;test0&lt;/option&gt;
              &lt;option value="1"&gt;test1&lt;/option&gt;
            &lt;/select&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/li&gt;
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>