Bootstrap
doesn't really disable the inner anchor it just looks disabled. The correct way to do this is to define the anchor
with no href
thus:
<li class="disabled"><a>Camps</a></li>
If you need to have the href
there, you will have to disable the click via JavaScript
or jQuery
:
$(document).ready(function() {
// For dynamically added elements
$(document).on("click", ".dropdown-menu li.disabled a", function() {
return false;
});
// For staticly loaded elemetns
/*
$(".dropdown-menu li.disabled a").click(function() {
return false;
});
*/
});
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<div class="dropdown">
<button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">Dropdown
<span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="E1ActivitySelect.html">Activity - E1 Administration</a></li>
<li><a href="#">Activity - E1</a></li>
<li class="divider"></li>
<li class="disabled"><a href="Camp.html">Camps</a></li>
<li><a class="dropdown-item" href="#">Hikes</a></li>
<li><a href="#">Major Events</a></li>
<li><a href="#">Pen Pals</a></li>
</ul>
</div>
If you are planning to add elements dynamically, you can attach the click
handler to the document
itself. The reason is because the event handlers in the jQuery
code, are being attached the first time the page loads, when you add elements after page load, the code that attaches the event handling has run already so you either reattach the event handling to the newly inserted elements or just add it to the container element for these freshly loaded elements. document
pretty much contains everyone so it's always a safe bet.