Reputation:
I have navigation bar in my website. following is the code with css
CSS
#navbar
{
width : auto;
height : 80px;
margin:15px 0px 0px 400px;
float:left;
}
#navbar ul
{
margin:0px;
padding:0px;
display:inline;
}
#navbar ul li
{
list-style:none;
float:left;
display:inline;
}
#navbar ul li a {
float:left;
display:inline;
font-family:arial;
font-size:16px;
font-weight:bold;
color:#505050;
margin: 20px 10px 0px 10px ;
padding : 5px;
width : 90px;
text-align:center;
border-radius:3px;
text-decoration:none;
}
#navbar ul li a:hover
{
background : #C84A30;
color:white;
}
#navbar ul li a.current {
background : #1D78B8;
color:white;
}
The HTML
<div id="navbar">
<ul>
<li><a href="#" class="current">Home</a></li>
<li><a href="#">About Us</a></li>
<li><a href="#">Products</a></li>
<li><a href="#">Contact Us</a></li>
<li><a href="#">Login</a></li>
</ul>
</div>
This is the Jquery i am using
$(document).ready(function(){
$("#navbar ul li a").hover(function() {
$(this).animate({ backgroundColor: "#C84A30" }, 100);
}, function() {
$(this).animate({ backgroundColor: "transparent" }, 300);
});
})
What i want is whenver the users hover any item of navigation bar, the background color should animate with red color. but, this also applies to current item ie. the current class. I dont want that the current class should be affected by jquery.
For eg : The current page is Home Page, then the home tab is modified with css current class. When the user hovers on any other tab i.e About us . the background should animate to red color.but the home tab should not be affceted.
Pls help
Upvotes: 0
Views: 144
Reputation: 65254
try this... using .not()
$(document).ready(function(){
$("#navbar ul li a").not(".current").hover(function() {
$(this).animate({ backgroundColor: "#C84A30" }, 100);
}, function() {
$(this).animate({ backgroundColor: "transparent" }, 300);
});
})
Upvotes: 3