All I am trying to accomplish is to be able to have an unordered list of links in which one is clicked, the parent list item is assigned the class "active." Once another link is clicked within that list, it checked to see if "active" is assigned, remove it from that list item, and add it to the most recent clicked links parent list item.
Example:
Step One - User has clicked the link "I am link two"
<ul>
<li><a href="#">I am link one</a></li>
<li class="active"><a href="#">I am link two</a></li>
</ul>
Step Two - User has now clicked the link "I am link one"
<ul>
<li class="active"><a href="#">I am link one</a></li>
<li><a href="#">I am link two</a></li>
</ul>
Pretty simple, but man I beat me up.
Something like the following ought to do it
Working Demo
This question is a bit old now, but I think there's still space for improvement.
"Traditional" local event binding:
Now, the same using event delegation via delegate() (jQuery +1.4.2). Lets you dynamically add extra >li>a without having to rebind the event:
Change "ul" to anything that matches exclusively the desired list(s), e.g. ".linksList", "#nav", etc.
Assumption: the UL element has the class 'linksList'.