You can solve this by investigating the click target when a click occurs. Find out what was clicked, then use that DOM element to find the right element to show/hide. I built a widget that does something like this, though it's not very flexible in its current form. Here's the relevant code:
$(document).on('click.' + this.id, '.toggleButton', function() {
$(this).toggleClass("fa-caret-right fa-caret-down");
$(this).parent().parent().next().slideToggle("fast");
});
The object "this" inside the event listener will be the actual DOM element clicked. This code looks at the clicked item, its grandparent's next sibling in the DOM, and performs a slideToggle on that element.
Here's my widget's gitHub repository: https://github.com/tieniber/ShowHideDivButton/