Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Jeremy Coleman
5,449 PointsToggling navigation on hover
I am making a navigation menu I wish to toggle upon click and hover.
I would like the menu to toggle off only when the cursor selects a item on the list or leaves the menu.
This is what I have for now.
$( '.toggle' ).click( function() {
$( 'ul.nav' ).slideToggle();
});
I have a navigation that will have 3 sections in the navigation. I don't have a solid version of what I have so here is a example of what I am trying to do.
<ul>
<li>
<ul>
<span>Navigation</span>
<li><a href="#">Home</a></li>
<li><a href="#">Portfolio</a>
<ul>
<li>
<a href="#">Template 1</a>
<a href="#">Template 2</a>
<a href="#">Template 3</a>
<a href="#">Template 4</a>
</li>
</ul>
</li>
<li><a href="#">About</a></li>
</ul>
<ul>
<span>Social Media</span>
<li><a href="#">Home</a></li>
<li><a href="#">Home</a></li>
<li><a href="#">Home</a></li>
</ul>
</li>
</ul>
1 Answer
Daniel Newman
Courses Plus Student 10,715 PointsYou can make it with pure CSS:
.menu_ul .submenu_ul { display:none; }
.menu_li > .submenu_ul { display: block; }
Or if you prefer JQuery-way: $('.someSelector').on("mouseenter", function(){ ...something happening... } );
Hope it will be helpful.