jQuery toggle children of div

前端 未结 5 1365
别那么骄傲
别那么骄傲 2020-12-06 13:11

I have the following HTML code:

Menu
submenu1
5条回答
  •  -上瘾入骨i
    2020-12-06 13:23

    Create anchors at Menu and Menu2

    Menu
    Menu2

    and script:

    $(".dim > a").click( function ( e ){ 
       e.preventDefault() // prevent default action - hash doesn't appear in url
       $( this ).parent().find( "div" ).toggleClass( "hidden" );
    });
    

    When click anyone of link submenu belonging to it will will appear or disappear

    Live demo: http://jsfiddle.net/ZxwpJ/

提交回复
热议问题