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")) {
menuMobile.classList.remove("menu-mobile--open");
}
 else {
menuMobile.classList.add('menu-mobile--open');
}
}


.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
Solution
August 19th 19 at 22:51
Have also have jquery slideToggle, for example if:

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


Then:
$(".mobHamburger").click(function(){
$(this).children(".menuMobile").toggleClass("menu-mobile--open").slideToggle("slow");
});
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 https://jsfiddle.net/ - 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