Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent the disappear of Dropdown menu using bootstrapDropdown when clicking on the list

I am using using bootstrap-dropdown to generate a Dropdown menu. I would like to prevent the disappearing of the menu when click on it.

I have implemented the following code, but it does not work. Any idea how to fix it?

HTML

<li class="dropdown notification">
  <a href="#" class="dropdown-toggle" data-toggle="dropdown">
    <span class="notification-label label label-info">
      <i class="icon-inbox icon-white"></i>
      <span class="notification-number">{{ unread_notifications }}</span>
    </span>
  </a>
  <ul class="dropdown-menu notification-list"></ul>
</li>

JS

events: {
  'click ul.notification-list': 'onClickNotification'
},

onClickNotification: function (e) {
  e.preventDefault();
  console.log(e);
},
like image 315
Lorraine Bernard Avatar asked Dec 27 '22 20:12

Lorraine Bernard


2 Answers

Did you try with event.stopPropagation?

onClickNotification: function (e) {
    e.stopPropagation();
    console.log(e)
},
like image 61
antonjs Avatar answered Dec 29 '22 09:12

antonjs


If you want to disable all auto closing of the dropdown you can just disable the listener

$('html').off('click.dropdown')

JSFiddle

like image 41
merv Avatar answered Dec 29 '22 11:12

merv