I need to open a Bootstrap dropdown menu via JavaScript. This answer suggests adding and removing the open
class, but when I try that, nothing happens. Adding a different class works fine. Is Bootstrap preventing me from doing this?
Working sample on JSFiddle.
HTML
<input type="button" value="Add Classes" />
<div class="dropdown">
<a data-toggle="dropdown" href="#">Dropdown Trigger</a>
<div class="dropdown-menu">Dropdown Content</div>
</div>
JS
$('input').click(function () {
$('.dropdown').addClass('open');
$('.dropdown').addClass('test-class');
});