Keep Bootstrap dropdown open on click

后端 未结 7 1019
我寻月下人不归
我寻月下人不归 2020-12-08 01:54

I use a bootstrap dropdown as a shoppingcart. In the shopping cart is a \'remove product\' button (a link). If I click it, my shoppingcart script removes the product, but th

7条回答
  •  没有蜡笔的小新
    2020-12-08 02:17

    This answer is just a sidenote to the accepted answer. Thanks to both the OP and Andres for this Q & A, it solved my problem. Later, however, I needed something that worked with dynamically added items in my dropdown. Anyone coming across this one might also be interested in a variation Andres' solution that works both with the initial elements as well as elements added to the dropdown after the page has loaded:

    $(function() {
        $("ul.dropdown-menu").on("click", "[data-keepOpenOnClick]", function(e) {
            e.stopPropagation();
        });
    });
    

    Or, for dynamically created dropdown menus:

    $(document).delegate("ul.dropdown-menu [data-keepOpenOnClick]", "click", function(e) {
        e.stopPropagation();
    });
    

    Then just put the data-keepOpenOnClick attribute anywhere in any of the

  • tags or its child elements, depending on your situation. E.G.:

    
    

提交回复
热议问题