This should be simple, but I just can’t get it to work
My list
<div id="ctMenu">
<ul>
<li><a href="#">WELCOME</a></li>
<li><a href="#">ABOUT US</a></li>
<li><a href="#">CONTACT</a></li>
</ul></div>
My CSS
#ctMenu { width:1010px; margin: 20px 0 0 0; padding:20px 0 20px 0}
#ctMenu ul { margin:0; padding:0;}
#ctMenu ul li { margin-left: 0; margin-bottom:0; display:inline;}
#ctMenu ul li a { padding: 10px 25px 9px 25px; background-color:green; text-decoration: none; color:Black; font-weight:bold; }
#ctMenu ul li a:hover {background-color:Gray; }
.selected { background-color: yellow; }
My jQuery
$(document).ready(function () {
$('#ctMenu ul li a').click(function () {
$('#ctMenu ul li a').removeClass('selected');
$(this).addClass('selected');
});
});
I’m just trying to set the css to the class “.selected” when someone clicks a link. Any suggestions?
EDIT: Here’s a JSFiddle
The problem is that you declared a stronger CSS rule
#ctMenu ul li athat overrides the.selected. Try this CSS rule instead: