0

I have a a dropdown button in a dropdown menu in Bootsrtap. When the button is clicked its dropdown items are not displayed and the parent dropdown closes. How do I override that behavior? Thank you
Andy
Here is a code snippet. It is based on SB Admin 2

<li class="dropdown">
    <a class="dropdown-toggle" data-toggle="dropdown" href="#">
        <i class="fa fa-tasks fa-fw"></i><i class="fa fa-caret-down"></i>
    </a>
    <ul class="dropdown-menu dropdown-tasks">
        <li>
            <div href="#" style="margin-right: 10px; margin-left: 10px">
                <p>
                    <strong>Pictures</strong>
                </p>
                <div>
                    <div class="btn-group">
                        <button type="button" class="btn btn-success dropdown-toggle" data toggle="dropdown" aria-expanded="false">
                            Save... <span class="caret"></span>
                        </button>
                        <ul class="dropdown-menu" role="menu">
                            <li class="menu-save-to-comp"><a href="#">To Computer</a></li>
                            <li class="menu-save-to-gdrive"><a href="#">To Google Drive</a></li>
                        </ul>
                    </div>
                </div>
            </div>
        </li>
    </ul>
</li>
2
  • It would help if you could set up a fiddle with your non-working code. Commented May 1, 2015 at 17:17
  • 1
    Her you go, here's a bootply with the non-working example. Commented May 1, 2015 at 17:21

2 Answers 2

2

See this working example bootply

I added a couple classes to your code and used this javascript:

$(".nestedDrop").click(function(e){
    e.stopPropagation();
    $(this).next().toggle();
});

$('.parentDrop').on('hidden.bs.dropdown', function(e){
    $(this).find('.nestedDrop').next().hide();
});

For this part of the HTML code

<li class="dropdown parentDrop">
    <a class="dropdown-toggle" data-toggle="dropdown" href="#">(click here for problem)<i class="fa fa-tasks fa-fw"></i><i class="fa fa-caret-down"></i>
    </a>
    <ul class="dropdown-menu dropdown-tasks">
        <li>
            <div href="#" style="margin-right: 10px; margin-left: 10px">
                <p>
                    <strong>Pictures</strong>
                </p>
                <div>
                    <div class="btn-group">
                        <button type="button" class="nestedDrop btn btn-success dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                            Now click this <span class="caret"></span>
                        </button>
                        <ul class="dropdown-menu" role="menu">
                            <li class="menu-save-to-comp"><a href="#">To Computer</a></li>
                            <li class="menu-save-to-gdrive"><a href="#">To Google Drive</a></li>
                        </ul>
                    </div>
                </div>
            </div>
        </li>
    </ul>
</li>
Sign up to request clarification or add additional context in comments.

Comments

0

I needed a multi level dropdown in bootstrap , not very long ago and i came up with the following snippet :

$(function(){
    $(".dropdown-menu > li > a.trigger").on("click",function(e){
        var current=$(this).next();
        var grandparent=$(this).parent().parent();
        if($(this).hasClass('left-caret')||$(this).hasClass('right-caret'))
            $(this).toggleClass('right-caret left-caret');
        grandparent.find('.left-caret').not(this).toggleClass('right-caret left-caret');
        grandparent.find(".sub-menu:visible").not(current).hide();
        current.toggle();
        e.stopPropagation();
    });
    $(".dropdown-menu > li > a:not(.trigger)").on("click",function(){
        var root=$(this).closest('.dropdown');
        root.find('.left-caret').toggleClass('right-caret left-caret');
        root.find('.sub-menu:visible').hide();
    });
});

FIDDLE HERE

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.