jQuery 要素の数を判定して数に応じて表示、非表示を切り替える方法

jQuery 要素の数を判定して数に応じて表示、非表示を切り替える方法

.php

<ul class="work_list">
  <?php $post_count = 0; if(have_rows('record_repeater')): while (have_rows('record_repeater')): the_row(); if($post_count < 5 ):  ?>
  <?php $post_count++; ?>
  <li>
    <div class="list_top flex">
      <p><span>受付日</span><?php the_sub_field('record_date'); ?></p>
    </div>
    <p class="works_txt"><?php the_sub_field('record_contents'); ?></p>
  </li>
  <?php endif; endwhile; endif; ?>
</ul>

 

.js

$(function(){
   //"div.categoryの要素内のliの数をカウント
   var num = $('.work_list').find('li').length;
   //"div.category内のul.catlist liが0件だったら
   if(num==5){
     $('.btn').css('display','block');
   }
});

 

category cloud