简体   繁体   English

如何使用 jquery 将菜单包装到子菜单中?

[英]how do I wrap my menu in to sub menu using jquery?

this is my site.这是我的网站。

this is how I finally make it look like这就是我最终让它看起来像的方式

I want to divide the the menu list items into two sub menu say menu left and right.我想将菜单列表项分成两个子菜单,比如左右菜单。 And then wrap them in a div.然后将它们包装在一个 div 中。 This is make it easy for me to style them and this way they would stay responsive as well.这使我可以轻松地为它们设置样式,这样它们也可以保持响应。

Now, I have been trying to achieve this by现在,我一直试图通过

jQuery( ".menu-item-580", ".menu-item-583",".menu-item-584",".menu-item-563").wrapAll("<div class='new' />").after(".menubar-brand");

I have trying this in browser console.我在浏览器控制台中尝试过这个。

I also tried same above code by using appendTo() instead of after()我还通过使用appendTo()而不是after()尝试了上述相同的代码

But, still no luck.但是,仍然没有运气。

In your code you're basically doing this:在您的代码中,您基本上是这样做的:

<ul>
    <li>
    <div class="new">
        <li>
        <li>
    </div>
    <li>
</ul>

which is not a valid markup.这不是有效的标记。

The easiest way to goup <li> s would be to assign different additional css classes to different parts of the list: goup <li>的最简单方法是将不同的附加 css 类分配给列表的不同部分:

<ul>
    <li class="group1">
    <li class="group1">
    <li class="group2">
    <li class="group2">
</ul>

Also, have a look at this: Is there a way to group `<li>` elements?另外,看看这个: 有没有办法对`<li>`元素进行分组?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM