I will try to briefly describe the essence of the problem: I have a mobile menu connected using the SlickNav plugin.

I need to create another drop-down menu with an arbitrary name in this menu. Here is my code:

var combinedMenu = $('.super-menu').clone(); //Это основное меню, которое я инициализирую var secondMenu = $('.side-category-left:first-child .box-category ul').clone(); //Это пункты меню, которые мне нужно добавить в созданное мною меню с названием "Каталог" var combmenu = $(combinedMenu.append('<li>Каталог<ul></ul></li>')); //Создаю пункт меню в переменной с названием "Каталог" и вложенным списком ul, в который хочу добавить li из переменной secondMenu secondMenu.children('li').appendTo(combmenu); //Пытаюсь добавить дочерные элементы в созданное меню "Каталог" combinedMenu.slicknav({ duplicate: false, label: '' }); 

The problem is that the elements are inserted after my menu. How do I insert secondMenu.children('li') into ul combmenu?

I really need help. Thank you in advance.

    1 answer 1

    Just that I answered almost the same question. https://ru.stackoverflow.com/a/620022/189649 There I create at the end of <li>Новое меню</li> , then through the selector I find this item and insert the list I need into it. The browser will figure out how to insert your node.

    You don’t need to create <ul></ul> or look for li > ul in this way, and you’ve only found li there and ul doesn’t, so it was inserted at the end of li, and not in ul.