Currently, I have implemented a function as a click event callback on a button. The purpose of this function is to toggle the class and provide a dropdown effect when the button is clicked. While this functionality works perfectly when the dropdown element is located next to the clicked button's parent element, it fails to work when the dropdown element is placed outside of the parent. The issue arises because there are multiple buttons with the same functionality on the page, causing all of them to trigger when just one is clicked:
https://jsfiddle.net/21xj96up/7/
$('.direction-button').on('click', function() {
$(this).next('.direction-dropdown').toggleClass('active');
});
.fade-in {
visibility: hidden;
opacity: 0;
transition: visibility 0s, opacity .3s ease-in-out, all .3s ease-in-out;
}
.active {
visibility: visible;
opacity: 1;
transform: translate(0, 0);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
<div class="contact-card">
<div class="contact-directions">
<a href="#" title="#" class="direction-button link-button animate-after">Directions</a>
</div>
<!-- end .contact-directions -->
<div class="contact-info"></div>
<!-- .contact-info -->
<div class="contact-partner"></div>
<!-- end .contact-info -->
</div>
<!-- end .contact-card -->
<div class="direction-dropdown fade-in">
<p>Display #1</p>
</div>
<div class="contact-card">
<div class="contact-directions">
<a href="#" title="#" class="direction-button link-button animate-after">Directions</a>
</div>
<!-- end .contact-directions -->
<div class="contact-info"></div>
<!-- .contact-info -->
<div class="contact-partner"></div>
<!-- end .contact-info -->
</div>
<!-- end .contact-card -->
<div class="direction-dropdown fade-in">
<p>Display #1</p>
</div>
I would greatly appreciate any advice or assistance on resolving this matter :)