title: how do i get the first parent that matches a class with jquery?
body: <p>I'm trying to grab the first parent element that matches a class check, but I'm having problems. My page could look like this:</p>
  
  <pre><code>&lt;input id="hidden1" type="hidden" value="5" class="includeds"&gt;
  &lt;h3&gt;header&lt;/h3&gt;
  &lt;ul class="groups"&gt;
      &lt;li&gt;&lt;input id="li1" type="checkbox" value="1" onclick="value()"&gt;&lt;/li&gt;
      &lt;li&gt;&lt;input id="li2" type="checkbox" value="2" onclick="value()"&gt;&lt;/li&gt;
      &lt;li&gt;&lt;input id="li3" type="checkbox" value="3" onclick="value()"&gt;&lt;/li&gt;
  &lt;/ul&gt;
  &lt;input id="hidden2" type="hidden" value="3" class="includeds"&gt;
  &lt;h3&gt;header2&lt;/h3&gt;
  &lt;ul class="groups"&gt;
      &lt;li&gt;&lt;input id="li4" type="checkbox" value="4" onclick="value()"&gt;&lt;/li&gt;
      &lt;li&gt;&lt;input id="li5" type="checkbox" value="5" onclick="value()"&gt;&lt;/li&gt;
      &lt;li&gt;&lt;input id="li6" type="checkbox" value="6" onclick="value()"&gt;&lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>So if I click on checkbox <code>li1</code>, I want to retrieve the value <code>"5"</code> from the hidden field above it.</p>
  
  <p>If I click <code>li5</code>, I want to get the value of <code>"2"</code> from the first hidden field above it, etc, etc.</p>
  
  <p>I'm trying this (inside the value() function), but it's not working, I keep receiving an undefined error.</p>
  
  <pre><code>var thevalue = $(this).closest(".includeds").value);
  </code></pre>
  
  <p>or</p>
  
  <pre><code>var thevalue = $(this).closest(".includeds").attr("value").toString());
  </code></pre>
  
  <p>I don't understand why they aren't working, any ideas? Thanks for any help.</p>