Codepen: http://codepen.io/Travo100/pen/DtwvG
I'm currently having an issue where I have a typical navigation menu setup and would like clicked on links to have a class added to them when clicked. However, I only want one link at a time to have this class on it. I've setup a codepen, and currently my code is making all the links posses this class, without removing it after the link is clicked on.
HTML
<nav>
<ul>
<li><a href="#" class="selected">Home</a></li>
<li><a href="#">About Us</a></li>
<li><a href="#">Samples</a></li>
<li><a href="#">Clients</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
CSS
a {
text-decoration: none;
padding: 10px;
margin-left: 5px
}
li {
float: left;
list-style: none
}
.selected, a:hover {
background-color: blue;
color: white;
}
JS
//When clicking on control list items
$("nav a").click(function() {
//Deselect sibling elements
$(this).siblings().removeClass( "selected" );
//Select clicked element
$(this).addClass( "selected" );
});
I'm new is jQuery/javascript so I apologize for this basic question.
Thank you for your help.