The whole problem is in the removeActiveMenuClass() function or how you use it. In this part of the code:
$( '.ibtn' ).click(function(e) { e.preventDefault(), e.stopPropagation(); removeActiveMenuClass(); $(this).children('.dropdown').addClass('open'); });
When clicking on the .ibtn element, the standard behavior and further event transfer are removed first (the second is most likely superfluous, but that’s not the point). Next, the removeActiveMenuClass() function is removeActiveMenuClass() , which removes the open class from everyone (including the current one) .dropdown , and then adds the open class again. Therefore, for the toggleClass() method to toggleClass() you need to delete the open class for everyone but the current one.
Alternatively, you can use the .not method:
$(function() { $(document).click(function() { removeActiveMenuClass(); }); $( '.ibtn' ).click(function(e) { e.preventDefault(), e.stopPropagation(); $('.ibtn').not(this).children('.dropdown').removeClass('open'); $(this).children('.dropdown').toggleClass('open'); }); function removeActiveMenuClass(){ $('.ibtn').children('.dropdown').removeClass('open'); } });
.dropdown { display: none; } .dropdown.open { display: block; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <a href="#" class="ibtn"> Click <div class="dropdown">I'm dropdown</div> </a>