How to Prevent Sub List to Slide Down and Up Parent List
Can you please take a look at
This Demo
and let me know how I can stop /prevent the sub menus to slide up the list. If you click the
Two
or Three you can see there are sub menus as Two _ 1 .. Two _ 4 and Three _ 1 to Three _ 4 now I would like to stop them sliding up the opened
musthidden class.
Here is the code I have:
HTML
- <ul id="slider">
- <li class="expandOnClick"> <a href="#">One</a></li>
- <li class="expandOnClick"> <a href="#">Two</a>
- <ul class="musthidden">
- <li><a class="prevent" href="#">Two _ 1</a></li>
- <li><a class="prevent" href="#">Two _ 2</a></li>
- <li><a class="prevent" href="#">Two _ 3</a></li>
- <li><a class="prevent" href="#">Two _ 4</a></li>
- </ul>
- </li>
- <li class="expandOnClick"> <a href="#">Three</a>
- <ul class="musthidden">
- <li><a class="prevent" href="#">Three _ 1</a></li>
- <li><a class="prevent" href="#">Three _ 2</a></li>
- <li><a class="prevent" href="#">Three _ 3</a></li>
- <li><a class="prevent" href="#">Three _ 4</a></li>
- </ul>
- </li>
- <li class="expandOnClick"> <a href="#">Four</a></li>
- </ul>
jQuery:
- $(".expandOnClick").click(function (e) {
- e.preventDefault();
- $(this).siblings().children(".musthidden").slideUp();
- if($(this).children(".musthidden").css('display') == 'none')
- {
- $(this).children(".musthidden").slideDown();}
- else
- {
- $(this).children(".musthidden").slideUp();
- }
- });
and CSS:
- .musthidden {display:none;}
- ul {list-style-type:none;}
- li {background-color:#2d2d2d;}
- li:hover {background-color:#ccc;}
- a { color:#fff;}
Thanks