I am working on a navigation menu with a mega menu feature. The current markup includes elements for a mega menu, but I need to remove some of these elements when the viewport is small.
Current Markup:
<ul class="megamenu-wrapper">
<li>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
</li>
<li>
<ul>
<li><a href="#">gang</a></li>
<li><a href="#">menu</a></li>
<li><a href="#">food</a></li>
</ul>
</li>
</ul>
Desired Markup:
<ul class="megamenu-wrapper">
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
<li><a href="#">gang</a></li>
<li><a href="#">menu</a></li>
<li><a href="#">food</a></li>
</ul>
I currently have two mega-menu-wrapper elements.
Attempted Solution:
var megaContents = $('.megamenu-wrapper li ul').contents();
$('.megamenu-wrapper li ul').replaceWith( megaContents );
This solution duplicates the list items in both mega menus and causes multiple repetitions of each element. Any help would be greatly appreciated.