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 trialAurelian Spodarec
10,801 PointsHow do you make pure JavaScript menu?
HI,
How do you make a pure JavaScript menu?
What is the different way of toggle from jQuery, to pure JS?
I got this
// Dropdown menu
var menuToggle = getElementsByClassName('m-headerSite__toggleMenu');
var menuNav = getElementsByClassName('m-mainMenu');
menuToggle.onclick = function() {
'a b'.split(' ').forEach(function(s) {
menuNav.classList.toggle(s);
});
}
<div class="l-container">
<div class="m-headerSite__header">
<div class="m-headerSite__brandHeader l-clearfix">
<div class="m-headerSite__logoWrapper">
<h1 class="m-headerSite__logo">Dorota Dishes</h1>
</div>
<div class="m-headerSite__toggleMenu">
<i class="fa fa-bars" aria-hidden="true"></i>
</div>
</div><!-- /m-headerSite__brandHeader -->
<nav class="m-mainMenu">
<ul class="m-mainMenu__list">
<li class="m-mainMenu__item--on"><a href="">Home</a></li>
<li class="m-mainMenu__item"><a href="">Blog</a></li>
<li class="m-mainMenu__item"><a href="">Recipe Index</a></li>
<li class="m-mainMenu__item"><a href="">Cooking Videos</a></li>
<li class="m-mainMenu__item"><a href="">About</a></li>
<li class="m-mainMenu__item"><a href="">Contact</a></li>
</ul>
</nav><!-- /c-headerSite__logoWrapper -->
</div>
</div><!-- /l-container -->
BUt not sure, about the toggle function in JS? as if there is any function like this?