title: jQuery: multiple checkboxes, get the value of the only checked one
body: <p>I've got a script that shows a value when one checkbox is checked and doesn't show any value when more than one checkbox is checked.</p>
  
  <p>This is working to a point.
  If I select one checkbox I get the value associated to it's nearest <code>class=list</code>, if I click a second checkbox I get nothing and that is correct.</p>
  
  <p>However when I unselect the second checkbox the alert shows it's value not the value of the last remaining checked check box.</p>
  
  <p>So how do I get the value of the only checked checkbox ?</p>
  
  <p>This is the layout of the checkbox and it's nearest <code>class list</code></p>
  
  <pre><code>&lt;tr&gt;
  &lt;td&gt;1&lt;/td&gt;&lt;td&gt;&lt;input type='checkbox' name='id[0]' id='0'/&gt;&lt;/td&gt;
  &lt;td class='list'&gt;&lt;span&gt;1234&lt;/span&gt;&lt;/td&gt;
  &lt;td&gt;&lt;span&gt;&lt;/span&gt;&lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>This is the jQuery I'm using :</p>
  
  <pre><code>$(document).ready(function () {
      var count;
      $(':checkbox').change(function() {
          count = ( $('input[type="checkbox"]:checked').length ) ;
          txt = $(this).closest('tr').find('.list').text();
          if (count == "1" ) {
              alert (txt)
          } 
      });
  });  
  </code></pre>
  
  <p>Here is a JSFiddle showing the issue : <a href="http://jsfiddle.net/f7qcuwkf/" rel="nofollow">http://jsfiddle.net/f7qcuwkf/</a>
  If you check option 1 the alert shows 1234.</p>
  
  <p>If you check option 3 then nothing shows (this is correct)  If you uncheck either option you see it's value and not the value of the remaining checked entry.  EG::</p>
  
  <p>Uncheck 3 I get 3456, NOT 1234 ( 1 is still checked )</p>
  
  <p>Any ideas how to resolve this ?</p>
  
  <p>Thanks</p>