I made a custom menu and I want to wrap an element with parent element through a script. element create from block-menu.html.twig Element: <li class="menu-item menu-item-level-1">

my js file:

var $ = jQuery.noConflict();
  $( ".menu-item-level-1" ).wrap( "<div class='new'></div>" );

The console does not display any errors, the script is connected. Checked with an error. Why is the element not wrapping?

  • Having a div as a child on a UL is invalid HTML that might be your problem Commented Jun 8, 2023 at 8:18
  • no, my problem is that the script runs before this element is created for some reason. I created a parent through the console, but I couldn’t through JS
    – nihdrupal
    Commented Jun 8, 2023 at 14:17
  • change to (window).load then if you think that's the case. But i'd still not recommend adding the div into a ul like that Commented Jun 8, 2023 at 15:21


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.