Hide all elements but the first 12

Hide all elements but the first 12

Hi,

The else if part of this code is not working. Does any one know why?

HTML
  1. <div class="row tile-list-wrapper tile-person-list">

  2. <div class="js-reveal-target">
  3. <!--#include file="tile-person.html" -->
  4. </div>

  5. <div class="js-reveal-target">
  6. <!--#include file="tile-person.html" -->
  7. </div>

  8. <div class="js-reveal-target">
  9. <!--#include file="tile-person.html" -->
  10. </div>

  11. <div class="js-reveal-target">
  12. <!--#include file="tile-person.html" -->
  13. </div>

  14. <div class="js-reveal-target">
  15. <!--#include file="tile-person.html" -->
  16. </div>

  17. <div class="js-reveal-target">
  18. <!--#include file="tile-person.html" -->
  19. </div>

  20. <div class="js-reveal-target">
  21. <!--#include file="tile-person.html" -->
  22. </div>
  23. <div class="columns">
  24. <button class="button hollow primary js-reveal-more-trigger">See more people</button>
  25. </div>

  26. </div>


JQuery
  1. var allInstances = $('.js-reveal-target'),
  2. revealMoreButtons = $('.js-reveal-more-trigger'),
  3.                         numberToShow = 2;

  4. var revealEffect = function () {

  5. allInstances.slice(0, numberToShow).show();

  6. if ($('.js-reveal-target:hidden').length > 0) {
  7. revealMoreButtons.on('click', function (e) {
  8. e.preventDefault();
  9. $('.js-reveal-target:hidden').slice(0, numberToShow).slideDown();
  10. $('html,body').animate({
  11. scrollTop: $(this).offset().top
  12. }, 1500);
  13. });
  14. } else if ($('.js-reveal-target:hidden').length == 0) {
  15.                         revealMoreButtons.text('See less people');
  16. revealMoreButtons.on('click', function (e) {
  17. e.preventDefault();
  18. $('.js-reveal-target').slice(0, numberToShow).hide();
  19. });
  20. }

  21. }; // End of revealEffect function