The following is a simple accordion menu ,:
Click B to compress the C list, and click C to change the style of its own and its parent node B. Different styles are changed during suspension.
First look at the page code, nesting of the list:
B C
B C
Css code, mainly set the background color and the Left Border style of the sub-menu, set the floating and selected style, and start to set the sub-menu not to display (click through js settings and then display ):
{:;:;}{:;:;:;:;:;:;:;}{:;}{:;}{:;:;}{:; :;:;:;:;:;:;:;}{:;:;:;}
Next, click the Event code:
$ (". ParentLi "). click (). children ('. childrenUl '". childrenLi "). click (". childrenLi "). removeClass ('selectedchildrenmenu '". parentLi "). removeClass ('selectedparentmenu '). parents (". parentLi "). addClass ('selectedparentmenu '). addClass ('selectedchildrenmenu'
It should be noted that the list nesting will cause event bubbling, so the click event in the sub-menu should be organized in the bubble. For details, see the API.