Hi I have this code in my CSS file
.topnav > li:hover:not(.active) > a {
background: #3e3e3e;
}
I want to achieve this with javascript . Could someone please help me with this thing, with some explanation ?
Assuming you're talking about a straight conversion to javascript, you could do the following (in jQuery);
$("li").not("active").children("a").hover(function(){
$(this).css({'background' : '#3e3e3e'});
}, function(){
$(this).css({'background' : 'youroldcolor'});
});
This works exactly like your css selector, looking first at the li's, ignoring the ones with an active class, then selecting the 'a' children. The use of (this) refers to the targetted element.
Updated to fix code problems.
Your HTML
<ul class="topnav">
<li onmouseover="StartHover()" onmouseout="OutHover()">aaaaaa</li>
</ul>
Your Javascript
<script>
function StartHover() {
$(".topnav li").css("background", "#3e3e3e");
}
function OutHover() {
$(".topnav li").css("background", "White");
}
</script>