You are supposed be using closest
(As subnav
is the ancestor of .team
elements)
$(this).closest('subnav').css('display', 'none');
It is a better idea to use a class
to change the style instead of defining them inline
.hide{
display: none;
}
Just add a class to apply the specific class. Lot more cleaner and less messy.
Also prevent the default action of the link being followed.
$('a.team').click(function (e) {
e.preventDefault();
$(this).closest('.subnav').addClass('hide')
});
// This is to remove the hide class
// which has more specificity
$('.nav > li').mouseover(function (e) {
$('.subnav').removeClass('hide')
});
You will encounter specificity
issues in this example.
When you set display:none
inline you can only override it by specifying inline again.
Use classes instead. And you see the same issue again. But writing a more specific class should solve the issue.. And your CSS should look like below for it to work.
CSS
.nav > li .subnav {
display:none;
}
.nav > li:hover .subnav {
display:block;
}
.nav > li .hide.subnav{
display: none;
}