javascript - Trigger jQuery on Bootstrap dropdown toggle -
i made bootply won't generate link, here's settings threw in there.
i want have jquery add class div when dropdown triggered, , remove class when dropdown hidden.
css:
.halfopacity { opacity: .5; } #switchmenu { top: 100px; } #sitedata { color: #fff; background-color: #000; } javascript:
$('#switchdropdown').on('show.bs.dropdown', function(){ $('#sitedata').addclass('halfopacity'); }); $('#switchdropdown').on('hide.bs.dropdown', function(){ $('#sitedata').removeclass('halfopacity'); }); html:
<a href="#" class="navbar-brand dropdown-toggle mobile-footer-brand" data-toggle="dropdown" id='switchdropdown'>test link</a> <ul class='dropdown-menu' id='switchmenu'> <li>horray!!!!</li> </ul> <div id='sitedata'>some stuff<br>moar stuff<br>even moar stuffs</div> right jquery never gets called based off of actions bootstrap says happen.
answered own question reading documentation more clearly.
events
all dropdown events fired @ .dropdown-menu's parent element.
the following changes fixed me:
javascript:
$('#wrap').on('show.bs.dropdown', function(){ $('#sitedata').addclass('halfopacity'); }); $('#wrap').on('hide.bs.dropdown', function(){ $('#sitedata').removeclass('halfopacity'); }); html:
<div id='wrap'> <a href="#" class="navbar-brand dropdown-toggle mobile-footer-brand" data-toggle="dropdown" id='switchdropdown'>test link</a> <ul class='dropdown-menu' id='switchmenu'> <li>horray!!!!</li> </ul> </div> <div id='sitedata'>some stuff<br>moar stuff<br>even moar stuffs</div>
Comments
Post a Comment