title: Filter and search div text by ul li click
body: <p>When you click the <code>li</code>, the <code>div</code>'s below should be filtered based on the selected <code>li</code> data values. This is working but for some reason, when you first load the page you have to click an <code>li</code> twice for the filter to work. </p>
  
  <p><strong><a href="http://codepen.io/omarel/pen/qaVNRG" rel="nofollow">Codepin Example</a></strong></p>
  
  <pre><code>&lt;div class="dropdown"&gt;
      &lt;a href="javascript:;" class="btn dropbtn selectBedrooms"&gt;select bedrooms &lt;span class="icon downarrow"&gt;&lt;/span&gt;&lt;/a&gt;
  
      &lt;ul id='filterFloorplans' onClick='filterFloorplans()' class="btn dropbtn"&gt;
          &lt;li data-value="1" class="dropdown-option"&gt;1 Bedroom&lt;/li&gt;
          &lt;li data-value="2" class="dropdown-option"&gt;2 Bedrooms&lt;/li&gt;
          &lt;li data-value="all" class="dropdown-option"&gt;all&lt;/li&gt;
      &lt;/ul&gt;
  &lt;/div&gt;
  
  &lt;div class="floorplanscontainer"&gt;
      &lt;div class="unit"&gt;1 bedroom&lt;/div&gt;
      &lt;div class="unit"&gt;1 bedroom&lt;/div&gt;
      &lt;div class="unit"&gt;2 bedrooms&lt;/div&gt;
  &lt;/div&gt;
  
  
  &lt;script&gt;
  
      function filterFloorplans()
      {
          $('.dropdown-option').click(function () {
              var theValue = $(this).attr('data-value');
  
              var rex = new RegExp(theValue);
  
              if(rex =="/all/"){
                  clearFilter()
              }else{
                  $('.unit').hide();
  
                  $('.unit').filter(function() {
                      return rex.test($(this).text());
                  }).show();
              }
               $('.dropdown ul.on').removeClass("on");
          });
      }
  
      function clearFilter()
      {
          $('.filterFloorplans').val('');
          $('.unit').show();
      }
  
      $('.selectBedrooms').click(function () {
          $('.dropdown ul').toggleClass("on");
      });
  
  &lt;/script&gt;
  </code></pre>