How would I go about remove the class from all elements except the next one?
For example:
<ul>
<li class="current"><a href="#">Trigger</a></li>
<li class="next"><a href="#">Trigger</a></li>
<li class="next"><a href="#">Trigger</a></li>
<li class="next"><a href="#">Trigger</a></li>
</ul>
Clicking on Trigger link a removes all the "next" classes from the li elements except the one directly below
I’m not worried about the whole set of code to achieve this. I’ve written everything that I need apart from this one thing of removing the class except on the next li?!
UPDATE: SOLVED
Seems I overlooked a simple solution which works well:
$(this).parent().siblings().not().next().removeClass('next');
Use the
.nextAllmethod to get all consecutive siblings after the current element. Then, reduce the set using.slice(1).The previous method only removes
nextfrom later items. If you want to affect all siblings, the following can be used:Another option: Remove the
nextclass from all elements, then add it to the next element.