开发者

jquery: 3 level vertical menu

开发者 https://www.devze.com 2023-04-10 10:08 出处:网络
I\'ve been looking around for a couple of hours for a 3 level vertical accordion menu. Something like this: http://sandbox.scriptiny.com/javascript-accordion/index.html

I've been looking around for a couple of hours for a 3 level vertical accordion menu. Something like this: http://sandbox.scriptiny.com/javascript-accordion/index.html

Something really simple is enough, but i cant get anything to work with 3 levels. Can anyone provide me with a jquery snippet to get me started? I've tried using

 $开发者_如何学运维('li').click(function(){

           $(this).children('ul').children('li').toggle();

        });

but it hides the submenu as well, not just the current childrens. Thanks


example from scratch:

<ul>
    <li>
        level 2
        <ul>
            <li>a</li>
            <li>b</li>
        </ul>
    </li>
    <li>
        level 2
        <ul>
            <li>
                level 3
                <ul>
                    <li>c</li>
                    <li>d</li>
                </ul>
            </li>

            <li>e</li>
            <li>f</li>
        </ul>
    </li>
</ul>

$('li').click(function(ev) {
    $(this).find('>ul').slideToggle();
    ev.stopPropagation();
});

demo: http://jsfiddle.net/aCaEG/


check ui.accordion and see if helps you.

in my opinion, dont try to do something that already exist.

0

精彩评论

暂无评论...
验证码 换一张
取 消