0

I made a bootply that won't generate a link, so here's my settings that I threw in there.

I want to have jQuery add a class to another div when this dropdown is triggered, and remove the class when the dropdown is 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 now the jQuery never gets called based off of the actions that Bootstrap says happen.

1 Answer 1

1

Answered my own question with reading documentation more clearly.

Events

All dropdown events are fired at the .dropdown-menu's parent element.

Bootstrap Documentation Here

The following changes fixed it for 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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.