title: using jquery to hide / show links based on checkbox
body: <p>I know this is a common question on this forum, but I can not find the solution specific. </p>
  
  <p>What I am trying to do is dynamically display HTML links based on checkbox selections.
  I'm having trouble figuring out what I'm doing wrong, the code does not seem to do anything at this point.</p>
  
  <p>Below is the code. </p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html lang="en"&gt;
  
  &lt;head&gt;
  &lt;meta charset="utf-8"&gt;
  &lt;meta name="description" content="GIT Courses" /&gt;
  
  &lt;title&gt;GIT Courses&lt;/title&gt;
  &lt;link href="courses3.css" rel="stylesheet" type="text/css"&gt;
  &lt;!-- We include the jQuery CSS, API, and UI from CDN in the Head --&gt;
  &lt;!-- Most browsers have CDN fed libraries already in cache, as they are used very frequently  --&gt;
  &lt;!-- This will speed up load times, reduce bandwidth use, and serve from closest geographical servers --&gt;
  &lt;!-- Ref: http://stackoverflow.com/questions/2180391/why-should-i-use-googles-cdn-for-jquery --&gt;
  &lt;link
      href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css"
      type="text/css" rel="Stylesheet" /&gt;
  &lt;script src="http://code.jquery.com/jquery-1.9.1.js"
      type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"
      type="text/javascript"&gt;&lt;/script&gt;
  
  &lt;/head&gt;
  
  &lt;body&gt;
  
  
  
      &lt;div id="wrapper"&gt;
  
          &lt;header&gt;
  
              &lt;div class=" headleft"&gt;&lt;/div&gt;
              &lt;div class="headright"&gt;
                  &lt;h1&gt;Graphic Information Technology&lt;/h1&gt;
              &lt;/div&gt;
  
              &lt;!-- end header --&gt;
          &lt;/header&gt;
  
          &lt;nav&gt;
              &lt;table class="navigation"&gt;
                  &lt;thead&gt;
  
                      &lt;tr&gt;
                          &lt;th&gt;&lt;a href="new2.html"&gt;home&lt;/a&gt;&lt;/th&gt;
                          &lt;th&gt;&lt;a href="courses3.html"&gt;courses&lt;/a&gt;&lt;/th&gt;
                          &lt;th&gt;&lt;a href="resources.html"&gt;resources&lt;/a&gt;&lt;/th&gt;
                          &lt;th&gt;&lt;a href="labs.html"&gt;lab&lt;/a&gt;&lt;/th&gt;
                      &lt;/tr&gt;
  
                  &lt;/thead&gt;
  
              &lt;/table&gt;
  
              &lt;!-- end nav --&gt;
          &lt;/nav&gt;
  
          &lt;!-- Begin HTML elements --&gt;
          &lt;h3&gt;Thank you for your interest in our Developer courses!&lt;/h3&gt;
          &lt;p&gt;Please select which campus resources you would like to explore
              more below:&lt;/p&gt;
          &lt;!-- Here is a "Field set" Array for the Resource Check Boxes --&gt;
          &lt;!-- We will leave the links out of the labels at this stage --&gt;
          &lt;fieldset id="checkboxArray"&gt;
              &lt;legend&gt;ASU Resources&lt;/legend&gt;
              &lt;label&gt;&lt;input type="checkbox" name="rescheck[]"value="Career Preparation" /&gt;Career Preparation&lt;/label&gt; 
              &lt;label&gt;&lt;input type="checkbox" name="rescheck[]" value="College Advising" /&gt;College Advising&lt;/label&gt; 
              &lt;label&gt;&lt;input type="checkbox" name="rescheck[]"value="Counseling Services" /&gt;Counseling Services&lt;/label&gt;
              &lt;label&gt;&lt;input type="checkbox" name="rescheck[]" value="Financial Aid" /&gt; Financial Aid &lt;/label&gt;
              &lt;label&gt;&lt;input type="checkbox" name="rescheck[]"value="Fitness &amp;amp; Recreation" /&gt; Fitness &amp; Recreation &lt;/label&gt; 
              &lt;label&gt;&lt;input type="checkbox" name="rescheck[]" value="Health Services" /&gt; Health Services &lt;/label&gt; 
              &lt;label&gt;&lt;input type="checkbox" name="rescheck[]"value="Housing" /&gt; Housing &lt;/label&gt;
              &lt;label&gt;&lt;input type="checkbox"name="rescheck[]" value="Library" /&gt; Library &lt;/label&gt;
              &lt;label&gt;&lt;input type="checkbox" name="rescheck[]" value="Parking" /&gt; Parking &lt;/label&gt; 
              &lt;label&gt;&lt;input type="checkbox" name="rescheck[]" value="Scholarships" /&gt; Scholarships &lt;/label&gt;
              &lt;label&gt;&lt;input type="checkbox" name="rescheck[]" value="Student Employment" /&gt; Student Employment &lt;/label&gt;
              &lt;label&gt;&lt;input type="checkbox" name="rescheck[]" value="Student Organizations" /&gt; Student Organizations &lt;/label&gt; 
              &lt;label&gt;&lt;input type="checkbox" name="rescheck[]" value="Tutoring Support" /&gt; Tutoring Support &lt;/label&gt;
              &lt;label&gt;&lt;input type="checkbox" name="rescheck[]" value="Writing Support" /&gt; Writing Support &lt;/label&gt;
          &lt;/fieldset&gt;
  
          &lt;!-- Here we display the resources selected.
       One way (well the only way I know how) is to Toggle visibility of DIVs based on selection. 
       The toggle is done within jQuery, here is the HTML side of it.
       Maybe not the best practice but it works, I never did take any classes on any of this :) --&gt;
  
          &lt;div class="myResources"&gt;
              &lt;p&gt;Here are the links to your selected resources:&lt;/p&gt;
              &lt;div  class="resource" resource-label="Career Preparation"&gt;
                  &lt;a href="https://students.asu.edu/careerguide/careerpreparation"&gt;Career
                      Preparation&lt;/a&gt;
              &lt;/div&gt;
              &lt;div  class="resource" resource-label="College Advising"&gt;
                  &lt;a href="https://technology.asu.edu/advising"&gt;College Advising&lt;/a&gt;
              &lt;/div&gt;
              &lt;div  class="resource resource-label="Counseling Services"&gt;
                  &lt;a href="https://students.asu.edu/counseling"&gt;Counseling
                      Services&lt;/a&gt;
              &lt;/div&gt;
              &lt;div  class="resource" resource-label="Financial Aid"&gt;
                  &lt;a href="https://students.asu.edu/financialaid"&gt;Financial Aid&lt;/a&gt;
              &lt;/div&gt;
              &lt;div  class="resource"
                  resource-label="Fitness &amp;amp; Recreation"&gt;
                  &lt;a href="http://fitness.asu.edu/"&gt;Fitness &amp; Recreation&lt;/a&gt;
              &lt;/div&gt;
              &lt;div  class="resource" resource-label="Health Services"&gt;
                  &lt;a href="https://students.asu.edu/health"&gt;Health Services&lt;/a&gt;
              &lt;/div&gt;
              &lt;div  class="resource" resource-label="Housing"&gt;
                  &lt;a href="http://housing.asu.edu/home"&gt;Housing&lt;/a&gt;
              &lt;/div&gt;
              &lt;div  class="resource" resource-label="Library"&gt;
                  &lt;a href="http://lib.asu.edu/"&gt;Library&lt;/a&gt;
              &lt;/div&gt;
              &lt;div  class="resource" resource-label="Parking"&gt;
                  &lt;a href="https://cfo.asu.edu/pts"&gt;Parking&lt;/a&gt;
              &lt;/div&gt;
              &lt;div  class="resource" resource-label="Scholarships"&gt;
                  &lt;a href="https://students.asu.edu/scholarships"&gt;Scholarships&lt;/a&gt;
              &lt;/div&gt;
              &lt;div  class="resource" resource-label="Student Employment"&gt;
                  &lt;a href="https://students.asu.edu/employment"&gt;Student Employment&lt;/a&gt;
              &lt;/div&gt;
              &lt;div  class="resource" resource-label="Student Organizations"&gt;
                  &lt;a href="http://asu.orgsync.com/"&gt;Student Organizations&lt;/a&gt;
              &lt;/div&gt;
              &lt;div  class="resource" resource-label="Tutoring Support"&gt;
                  &lt;a href="https://studentsuccess.asu.edu/"&gt;Tutoring Support&lt;/a&gt;
              &lt;/div&gt;
              &lt;div  class="resource" resource-label="Writing Support"&gt;
                  &lt;a href="https://studentsuccess.asu.edu/writingcenters"&gt;Writing
                      Support&lt;/a&gt;
              &lt;/div&gt;
  
              &lt;!-- end of content wrapper --&gt;
          &lt;/div&gt;
          &lt;!--  End of HTML Elements --&gt;
          &lt;!--  Suggested best practice is to put all Scripts at the bottom of the page, just before the End of Body Tag --&gt;
          &lt;!--  This is to speed up page loading time --&gt;
          &lt;!--  Ref: http://stackoverflow.com/questions/2105327/should-jquery-code-go-in-header-or-footer --&gt;
          &lt;!-- jQuery code begins here --&gt;
          &lt;script type="text/javascript"&gt;
      // We place all jQuery code inside this "Document Ready" handler to ensure everything loaded completely before running code
      $(document).ready(function() {
          // bind to click function
          $('input[type="checkbox"]').click(function() {
              // test if any are checkboxes in the array are checked
              if ($('input[name="rescheck[]"]:checked').length &gt; 0) {
                  // hide all resources until...
                  $('.resource &gt;div').hide();
                  // we loop checked boxes and show div.
                  $("input[name='rescheck[]']:checked").each(function() {
                      $('.resource &gt;div[resource-label=' + this.id + ']').show();
                  });
                  // hmm... at least that was the idea
                  //FIXME: Why didn't this hide?
              } else {
                  // none checked - hide all
                  $('.resource &gt;div').hide();
              }
          });​​
      }); 
  &lt;/script&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>