I am trying to create a really simple universal switch function in which the switch "switch" has a class .toggle, and then I want it to be the toggle()next element that the class has .toggle-content.
HTML example:
<p>
<a href="#" class="toggle">Toggle the thing</a>
</p>
<p class="toggle-content hidden">I'm totally hidden right now</p>
So, now I would switch this with:
$(".toggle").click(function() {
$(this).parent().next('.toggle-content').toggle();
});
The problem is that if the class .toggleis deeper in the DOM, I must continue to stick more parent()depending on how much it is / not.
So, how can I just select the next instance .toggle-contentwithout using a bunch parent()and next()?
source
share