Given this website: link text
How would one find an element and remove any class=selected and add it to the correct link? That way when history, models, and the like links will look become selected when clicked upon.
Given this website: link text
How would one find an element and remove any class=selected and add it to the correct link? That way when history, models, and the like links will look become selected when clicked upon.
$("a").click(function(e) {
$("a.selected").removeClass("selected");
$(this).addClass("selected");
});
The following code should do the trick in your case..
// when clicking a link inside the sub-navigation list
$('#sub-navigation a').click(function(){
// first remove the selected class from the active one
$('#sub-navigation li.selected').removeClass('selected');
// then find the parent li of the clicked element and add the selected class
$(this).parents('li').addClass('selected');
});
(it is tested on your example page and it works as expected..)