I'm trying to show/hide my div elements using slidetoggle and slideDown. Its working perfectly fine.
Now what I'm trying to do is, I want to addClass 'visible-divs' to the visible divs only and removeClasswhen they get hidden.
Problem is, the class is added succesfully but it doesn't remove the class when it slides up to hide them. What am I doing wrong?
$(".OffersContainer > div:gt(0)").hide();
$(".OffersContainer > span").click(function() {
this.clickCount = (this.clickCount || 0) + 1
var command = this.clickCount % 3 === 0 ? 'slideToggle' : 'slideDown';
$(this).siblings(this.clickCount % 3 === 1 ? "div:lt(3)" : "div:gt(0)")[command]();
$('.pan-box').filter(':visible').addClass("visible-divs");
$('.pan-box').filter(':hidden').removeClass("visible-divs");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="OffersContainer">
<div class='pan-box'>A</div>
<div class='pan-box'>B</div>
<div class='pan-box'>C</div>
<div class='pan-box'>D</div>
<div class='pan-box'>E</div>
<span>Show more</span>
</div>