Packery -- jquery show/hide works but not the other way

264 views Asked by At

I have a bizzare problem using Packery. Below is my code.

If I toggle from show(default) to hide when I select from the dropdown menu it works fine.

When I hide it on load and would like to show the class when I select from drown down, it does NOT work. It just shows me the last picture ALWAYS.

I cant seem to figure out what the problem is. Could anyone help?

<select id="DateFilter">
    <option selected>Choose Date</option>
    <option id="yesterday">yesterday</option>
    <option id="today">today</option>
</select>

<div id="container" class="js-packery" data-packery-options='{ "itemSelector": ".item", "gutter": 0 }'>
  <div class="yesterday">

    <div class="item">
      <figure><img src="pic1.jpg" width="100%"><figcaption>Pic 1</figcaption></figure>
    </div>

    <div class="item">
      <figure><img src="pic2.jpg" width="100%"><figcaption>Pic 2</figcaption></figure>
    </div>

    <div class="item">
      <figure><img src="pic3.jpg" width="100%"><figcaption>Pic 3</figcaption></figure>
    </div>

  </div>
</div>

<script>
    $(document).ready(function(){
      $(".yesterday").show();
      $("#DateFilter").change(function(){
        if($(this).find("option:selected").attr("id")=="yesterday"){
           $(".yesterday").hide();
        }
      });
   });
</script>
2

There are 2 answers

1
Mohamed-Yousef On
<select id="DateFilter">
  <option selected>Choose Date</option>
  <option value="yesterday" id="yesterday">yesterday</option>
  <option value="today" id="today">today</option>
</select>

and change

   if($(this).find("option:selected").attr("id")=="yesterday"){

with

   if($(this).val() == 'yesterday'){
1
Vipul Hadiya On

Code is working as it should be. You have explained you problem partially> Images can be shown on document load and it become hidden when you select Yesterday.