I have a top navigation bar, and some of its elements trigger dropdown menus / slides.
My problem is that whenever I click on an item or virtually any area in the drop-down list, the drop-down menu crashes.
I need help figuring out how to avoid dropping a dropdown when a child is clicked (or anywhere in the dropdown list, since I would like to take into account random clicks inside the dropdown, but this doesn’t actually click on the child )
Here is the basic HTML structure:
<ul class="dropdown"> <li><a href="#" class="noclick nojs">Select your Topic</a> <ul class="nojs" > <li><a href="#">Link 1</a></li> <li><a href="#">Link 2</a></li> <li><a href="#">Link 3</a></li> </ul> </li> </ul>
My JavaScript:
$('.dropdown li').click(function() { //Hide all other drop downs that are visible, and remove the class 'selected' $(this).siblings('.selected').removeClass('selected').find('ul:visible').slideUp('fast'); //Show/Hide dropdowns $(this).toggleClass('selected'); $('ul:first', this).stop(true, true).slideToggle('fast'); });
Here demo
Any help is greatly appreciated.
Thanks.
source share