1

I am using bootstrap and am trying to disable an li so when the user clicks on one of the li elements in the dropdown nothing happens. Currently when I click on the top li element the dropdown closes. I want it to stay open. Most of the resources I have found have been about disabling links. I want to create a drop down similar to the one on Facebook.

Here is my html

<div class="dropdown">
  <button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">Dropdown Example
  <span class="caret"></span></button>
  <ul class="dropdown-menu">
    <li id="test"><a href="#">HTML</a></li>
    <li><a href="#">CSS</a></li>
    <li><a href="#">JavaScript</a></li>
  </ul>
</div>

here is my css

#test{
  background-color:red;
  pointer-events: none;
}

and here is a link to jsfiddle.

https://jsfiddle.net/aaronmk2/DTcHh/67643/

Aaron
  • 4,380
  • 19
  • 85
  • 141
  • Possible duplicate of [Avoid dropdown menu close on click inside](https://stackoverflow.com/questions/25089297/avoid-dropdown-menu-close-on-click-inside) – APAD1 May 10 '18 at 18:42
  • What do you want to do when a user clicks on any one the `
  • `?
  • – Abrar May 10 '18 at 18:43
  • @Abrar, currently when I click on the
  • the dropdown closes. I want the drop down to stay open.
  • – Aaron May 10 '18 at 18:45
  • Possible duplicate of [How do I prevent my dropdown from closing when clicking inside it?](https://stackoverflow.com/questions/23031635/how-do-i-prevent-my-dropdown-from-closing-when-clicking-inside-it) – showdev May 10 '18 at 18:51
  • $('li').on('click', function(event){ // The event won't be propagated up to the document NODE and // therefore delegated events won't be fired event.stopPropagation(); }); – Naga Sai A May 10 '18 at 18:53
  • Are you trying to target just the disabled menu item at the top, or all of them? – Tank May 10 '18 at 19:09