I am trying to make the red line move above the hovered menu item, then disappear when no menu item is selected. I am very new to Jquery so really stuck on how to do this.
Does anyone have any ideas?
The code is at http://jsfiddle.net/xpvt214o/276727/
HTML
<div class="topnav" id="myTopnav">
<a href="#home" id="homeLink" class="active">Home </a>
<div class="dropdown">
<button class="dropbtn">About
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
<a href="#">Our Vision</a>
<a href="#">Our Story</a>
<a href="#">Leadership</a>
</div>
</div>
<a href="#contact">News</a>
<div class="dropdown">
<button class="dropbtn">Get Involved
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
<a href="#">Events</a>
<a href="#">Social Media</a>
<a href="#">Regional Branches</a>
</div>
</div>
<a href="#about">Donate</a>
<a href="#about">Join</a>
<a href="javascript:void(0);" style="font-size:15px;" class="icon" onclick="myFunction()">☰</a>
</div>
<div class="main-nav__line" style="width: 75px; left: 288.594px;"></div>
CSS
.topnav {
overflow: hidden;
background-color: #e6e6e6;
font-family: 'Lato', sans-serif;
font-style: normal;
font-variant: normal;
}
.topnav a {
float: left;
display: block;
color: black;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 2em;
}
.active {
color: white;
}
.topnav .icon {
display: none;
}
.dropdown {
float: left;
overflow: hidden;
}
.dropdown .dropbtn {
font-size: 2em;
border: none;
outline: none;
padding: 12px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #afafaf;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.topnav a:hover, .dropdown:hover .dropbtn {
color: #2d9e94;
}
.dropdown-content a:hover {
background-color: #ddd;
color:#2d9e94;
}
.dropdown:hover .dropdown-content {
display: block;
}
.main-nav__line {
position: absolute;
top:0;
height: 4px;
width: 0px;
background-color: #e91d27;
transition:all 0.2s ease-in-out;
left:150px;
}
Jquery
$('ul.myTopnav').hover(function(){ =
$('.main-nav__line'.toggle());
})
I have tried to get it to hover using the Jquery "hover" command but I cannot get it to work.