Reputation: 321
...and slide up on hover out, but not only. important!: forbidden to follow the parent link of submenu if clicked accidentaly.
below is quite similar what i would like to achieve, difference is: submenu slides down/up on click:
html:
<ul id="toggle">
<li> <a href="/">Home</a>
<li> <a href="/products">Products</a>
<ul class="dropdown-menu" role="menu">
<li><a href="/products/potatos">Potatos</a></li>
<li><a href="/products/carrots">Carrots</a></li>
</ul> </li>
<li><a href="/contact">Contact</a>
<ul class="dropdown-menu" role="menu">
<li><a href="/contact/people">People</a></li>
<li><a href="/contact/map">Map</a></li>
</ul>
</li>
</ul>
javascript:
$('#toggle li:has(.dropdown-menu)').on('click', function (event) {
if ($(event.target).parents('.dropdown-menu').length > 0) {
event.stopPropagation();
} else {
event.preventDefault();
}
$(this).find('ul').slideToggle();
});
Upvotes: 0
Views: 544
Reputation: 126
$('#toggle li:has(.dropdown-menu)').hover(function (event) {
if ($(event.target).parents('.dropdown-menu').length > 0) {
event.stopPropagation();
} else {
event.preventDefault();
}
$(this).find('ul').slideToggle();
});
hope this will help u.
Upvotes: 1
Reputation: 2533
May be something like this?
$('#toggle li:has(.dropdown-menu)').hover(function (event) {
if ($(event.target).parents('.dropdown-menu').length > 0) {
event.stopPropagation();
} else {
event.preventDefault();
}
$(this).find('ul').slideToggle();
});
Upvotes: 0