I'm trying to make a navigation bar where the current tab you're visiting has a different background color, by adding a CSS class (the "clickedNav" class). I have a loop to iterate through and remove the color (so only the current tab is highlighted), and then I add the color to the clicked link. Right now, it's adding the class (clickedNav) successfully, but my loop to remove them beforehand isn't removing them (I'm seeing lots of "HEYS", but no "yup"s). Here's the relevant code:
$('.navlink').click(function(e){
console.log("HEY");
var self = $(this);
$('.navlink').each(function(i) {
if($('.navlink').hasClass('.clickedNav')){
console.log("yup");
$('.navlink').removeClass('clickedNav');
}
});
$(this).addClass('clickedNav');
event.stopPropagation();
});
What am I doing wrong?
EDIT: Thanks for the help folks. See scrblndr3's response for the fix to my code as posted, and Pinpickle's response for a more efficient resolution.