'How can I reveal my site's sub-menu for mobile?
I am trying to reveal my sub-menu using jQuery. It is a rewrite of the code in the image using jQuery.
https://github.com/alwayswantedtocode/xpress-cars-web-dev-
Code I am trying to rewrite using jQuery:

$(document).on("click", ".navigation", function(event) {
const target = $(event.target),
mediaSize = 991;
homeSubList = $(event.target.parentElement),
revealSubMenu = $(homeSubList).add('.sub-menu');
if ($(target).attr("data-toggle") && (window.innerWidth <= mediaSize)) {
$(homeSubList).toggleClass("active");
$(revealSubMenu.height()) = $(revealSubMenu).prop('scrollHeight') + 'px';
};
});
Solution 1:[1]
Here it is:
$(document).on("click",".navigation", function(event){
const mediaSize = 991;
if ($(event.target).attr('data-toggle') !== undefined && window.innerWidth <= mediaSize) {
const menuItemHasChildren = $(event.target).parent();
$(menuItemHasChildren).addClass('active');
const subMenu = $(menuItemHasChildren).find('.sub-menu');
$(subMenu).css('maxHeight', $(subMenu).prop('scrollHeight'));
}
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Nelio |
