I am new to JS and jQuery. I am trying to achieve the following: when I hide the content of the panel I want to use the glyphicon-folder-close icon, and when I show the content of the panel I want to use the glyphicon-folder-open icon.
This is part of my view (I'm using Rails):
<div class="panel panel-warning">
  <div class=panel-heading style="font-weight: bold;">
    <h4 class="panel-title">
      <a data-toggle="collapse" data-parent="#panel" href="#saleitem" class="panel-toggle">
        <span class="glyphicon glyphicon-folder-close"  id="icontoggle"></span>
        Sale Items
      </a>
    </h4>
  </div>
  <div id="saleitem" class="panel-collapse collapse">
     <div class="panel-body">
       <div class="table-responsive">
         <table class="table table-hover table-condensed">
           <thead>
And this is my jQuery:
$(document).ready(function(){
  $('#saleitem').on('show', function () {
    $(".glyphicon-folder-close").removeClass("glyphicon-folder-close").addClass("glyphicon-folder-open");
  });
  $('#saleitem').on('hide', function () {
      $(".glyphicon-folder-open").removeClass("glyphicon-folder-open").addClass("glyphicon-folder-close");
  });
});
Thanks in advance!