I’m modifying an accordion script to add the class active to the link that gets clicked, but for sub items, I’m having an issue.
Basically, if you click on a child of the accordion, I need it to also add the class active without removing it from the parent. Like this
parent-item
parent-item (active)
sub-item
sub-item (active)
sub-item
parent-item
parent-item
Here’s the bit of script currently:
$("#menu li a").removeClass("active");
$(this).addClass("active");
Thanks, just post a comment if you need clarification.
EDIT:
The children elements aren’t technically children of the same thing, so .parent() won’t work.
<li>
<a href="#">parent-item</a>
<ul>
<li><a href="#">sub-item</a>
</ul>
</li>
You can try:
This will remove the .active on the same level elements