I have some code working that turns the "active" class on and off when you click on a div wrapper div.
However, I would like one of these divs to have an active class at a time. Right now I can click them all and everyone will have an active class. I'm not sure how to remove a class from all other divs except the ones I just clicked on.
I tried to use .parent (), but it didn't seem to work / I don't think I used it correctly.
HTML
<div class="variation_form_section"> <div class="select"> <div class="swatch-wrapper"></div> <div class="swatch-wrapper"></div> <div class="swatch-wrapper"></div> </div> </div>
Js
<script> $(document).ready(function(){ $(".variation_form_section .select div").each(function() { $(this).click(function() { if($(this).hasClass( "active" )){ $(this).removeClass( "active" ); }else{ $(this).addClass( "active" ); } }); }); }); </script>
source share