Reputation: 5553
Having a stupid issue, simply want to add a class to an li a when it's sub menu is visible. It is cascading and adding the class to all li a, even the one's in the sub menu.
<ul id="nav">
<li><a href="#" target="_self">HOME</a></li>
<li class="dropdown"><a href="#" target="_self">SYSTEM MANAGER<span aria-hidden="true" data-icon=""></span></a>
<ul>
<li><a href="#" target="_blank">Link 1</a></li>
</ul>
</li>
</ul>
JS
$('li.dropdown').on('mouseenter mouseleave', function(e){
e.preventDefault();
if (e.type === 'mouseenter')
$(this).addClass('hilight');
else
$(this).removeClass('hilight');
});
CSS
body header #headerContain nav#nav-wrap ul#nav li.dropdown.hilight a {
color: #db4105;
}
How do I get it to apply only to the parent li.dropdown a and not have it cascade to the children li a's?
Upvotes: 0
Views: 223
Reputation: 13421
You should use child-selector, just change your css,
body header #headerContain nav#nav-wrap ul#nav li.dropdown.hilight > a {
color: #db4105;
}
Upvotes: 2