I am currently working on developing a navigation menu with four levels of depth. The menu displays three levels at a time, and when the user reaches the fourth level, the first level should move to the left to make room for the second, third, and fourth levels.
However, I'm encountering an issue where clicking on a menu item in the third level (without children) also causes the menu to move left.
For example: Clicking on Menu-item1 > Menu-item1.2 > Menu-item1.2.2 > Menu-item1.2.2.1 moves the menu left even though Menu-item1.2.2.1 has no children.
How can I adjust my code so that the menu only moves left if it has child sub-menus?
Below is the code snippet: