Show / Hidden Content

I need help on this toogle function. How to make the name change, for example : when the "box" show it only display SHOW and when the "box" hidden, it only display HIDE.

Now Show / Hide will display on both Show and Hidden.

  
$(document).ready(function(){
    $(".show").click(function(){
        $(".apaansi").toggle();
    });
});
.box {
  border:1px solid #dedede;
  padding:1%;
  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div id="uniquename">
  
  <div class="apaansi">
  
    <div class="box col-lg-12 col-md-12 col-sm-12 col-xs-12"> Search </div>
  
  </div>
  
   
  <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<a href="#" class="show show-car"> Show / Hide <i class="fa fa-chevron-down"></i> </a>
</div>
  
</div>

Answers 1

  • you can simply use a counter for that..

    here's a fiddle: https://jsfiddle.net/LL5xhapL/

       $counter = 0;
       $(".show").click(function(){
            if($counter % 2)
            {
              $(this).html('Hide <i class="fa fa-chevron-down"></i>');
            }else{
              $(this).html('Show <i class="fa fa-chevron-right"></i>');
              $counter = 0;
            }
            $counter++;
            $(".apaansi").toggle();
        });
    

Related Articles