How to make an analogue of JS slideToggle on?

Mobile menu is expanded when you click on the picture using the slideToggle function.
I want to transform into classes, and using js to add or remove a class. The problem is that the animation only works if to specify height in pixels, and I want the height of the block was equal to the content. Besides, the menu has another submenu which is also unfolding. Tell me friends

mobHamburger.onclick = function () {
 if (menuMobile.classList.contains("menu-mobile--open")) {
 else {

.menuMobile {
width: 100%;
height: 0;
transition: all .5s;

.menu-mobile--open {
height: 100%;
August 19th 19 at 22:47
2 answers
August 19th 19 at 22:49
August 19th 19 at 22:51
Have also have jquery slideToggle, for example if:

<div class="mobHamburger">
 <div class="menuMobile">
 Submenus with any height

A little incorrectly asked question: I would like to hang it on the classes and the js 'th switch them - Alford.Mohr commented on August 19th 19 at 22:54
For good, from the point of view is correct code for CSS classes, attributes, and id for JS) the Menu is easier and better to do a tree structure and to catch just the direct descendants. - Ashleigh75 commented on August 19th 19 at 22:57
I understand and want to do, but the animation using css is not working in my code, so I wanted to know how to fix - Alford.Mohr commented on August 19th 19 at 23:00
Put your code here - Ashleigh75 commented on August 19th 19 at 23:03
it will not work. Subverted with max-width - rudy commented on August 19th 19 at 23:06

Find more questions by tags JavaScriptWeb Development