How to target elements that are same class as sibling element?

How to target elements that are same class as sibling element?

When selectbox1 (.select-selected) is clicked on, dropdown1 (.select-open) displays. Correspondingly when selectbox2 is clicked on while dropdown1 is still open, dropdown1 will close, while dropdown2 will open. How do I do this? My current code does not work. My dropdown class .select-open is a sibling element to the selectbox element (.select-selected).


  1. <div class="select-selected"></div> <div class="select-items select-open"></div>
  2. $(".select-selected").click(function() { if ($(this).siblings(".select-items:not(this)").hasClass("select-open")) { // hide all select-open dropdowns that are not (this) select-open } $(this).show(); });