I have a drop-down button with a list of things that are tied to different parts of the page. This drop-down menu is for mobile devices only.
However, the problem is that the popup does not close after I click on it. Anyway, can I close it by pressing? I tried looking around, but that would not work on mine.
<div id="mobile-dropdown" class="nav2 w" data-spy="affix" data-offset-top="350"> <div class="container"> <div class="pull-left" style="margin-top:3px; margin-right:3px;">Jump to </div> <div class="pull-left"> <div class="btn-group mob-fl"> <button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown" aria-expanded="false"> Categories <span class="caret"></span> </button> <ul class="dropdown-menu" role="menu"> <li><a href="#1">One</a></li> <li><a href="#2">Two</a></li> <li><a href="#3">Three</a></li> <li><a href="#4">Four</a></li> </ul> </div> </div> </div> </div>
I also looked at bootstrap js itself and caught this line:
if ('ontouchstart' in document.documentElement && !$parent.closest('.navbar-nav').length) { // if mobile we use a backdrop because click events don't delegate $('<div class="dropdown-backdrop"/>').insertAfter($(this)).on('click', clearMenus) }
Is this the reason why it will not be closed? Is there a workaround to make it work?
EDIT:
So, with some help, I got this script:
$('document').ready(function() { $("a.dropdown-toggle").click(function(ev) { $("a.dropdown-toggle").dropdown("toggle"); return false; }); $("ul.dropdown-menu a").click(function(ev) { $("a.dropdown-toggle").dropdown("toggle"); return false; }); });
My javascript is pretty weak, as I actually edited it so that it only works in my div with reversal output.
Until now, I have updated my script to this:
$('document').ready(function() { $("#subject_cat_mob .dropdown-toggle").click(function(ev) { $("#subject_cat_mob .dropdown-toggle").dropdown("toggle"); return false; }); $("#subject_cat_mob ul.dropdown-menu a").click(function(ev) { $("#subject_cat_mob .dropdown-toggle").dropdown("toggle"); return false; }); });
It works the way I want. But the drop-down list will not open again after the first time.