user3240544
user3240544

Reputation: 267

Trivial JavaScript / Bootstrap dropdown issue

Basically what I have is 3 dropdown menus, and I need only one to be active, so that when I choose something from it, the rest should become active as well. So what I've done so far is I've added the disabled class and now I have the first one active, while the rest 3 - disabled. My question is - how to make them active as soon as I choose something from the first dropdown

 $(document).ready(function () {

        $('#Test #firstId .dropdown-menu li a').click(function () {
            var selText = $(this).text();
            $(this).parents('.btn-group').find('.dropdown-toggle').html(selText + ' <span class="caret"></span>')
        });

        $('#Test #secondId .dropdown-menu li a').click(function () {
            var selText = $(this).text();
            $(this).parents('.btn-group').find('.dropdown-toggle').html(selText + ' <span class="caret"></span>')
        });

        $('#Test #thirdId .dropdown-menu li a').click(function () {
            var selText = $(this).text();
            $(this).parents('.btn-group').find('.dropdown-toggle').html(selText + ' <span class="caret"></span>')
        });
        $('#Test #fourthId .dropdown-menu li a').click(function () {
            var selText = $(this).text();
            $(this).parents('.btn-group').find('.dropdown-toggle').html(selText + ' <span class="caret"></span>')
        });

    });

And here are my dropdowns:

 <div class="btn-group" id="firstId">
                            <button class="btn btn-default dropdown-toggle" type="button"
                                    data-toggle="dropdown">
                                Store
                                <span class="caret"></span></button>
                            <ul class="dropdown-menu" role="menu" aria-labelledby="menu1">
                                <li role="presentation"><a role="menuitem" tabindex="-1" href="#">1</a></li>
                                <li role="presentation"><a role="menuitem" tabindex="-1" href="#">2</a></li>
                                <li role="presentation"><a role="menuitem" tabindex="-1" href="#">3</a>
                                </li>
                                <li role="presentation" class="divider"></li>
                                <li role="presentation"><a role="menuitem" tabindex="-1" href="#">About Us</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="col-md-3">
                    <div class="dropdown">
                        <div class="btn-group" id="secondId">
                            <button class="btn btn-default dropdown-toggle disabled" type="button"
                                    data-toggle="dropdown">
                                Catalog
                                <span class="caret"></span></button>
                            <ul class="dropdown-menu" role="menu" aria-labelledby="menu1">
                                <li role="presentation"><a role="menuitem" tabindex="-1" href="#">1</a></li>
                                <li role="presentation"><a role="menuitem" tabindex="-1" href="#">2</a></li>
                                <li role="presentation"><a role="menuitem" tabindex="-1" href="#">3</a>
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="col-md-3">
                    <div class="dropdown">
                        <div class="btn-group" id="thirdId">
                            <button class="btn btn-default dropdown-toggle disabled" type="button"
                                    data-toggle="dropdown">
                                Categories
                                <span class="caret"></span></button>
                            <ul class="dropdown-menu" role="menu" aria-labelledby="menu1">
                                <li role="presentation"><a role="menuitem" tabindex="-1" href="#">1</a></li>
                                <li role="presentation"><a role="menuitem" tabindex="-1" href="#">2</a></li>
                                <li role="presentation"><a role="menuitem" tabindex="-1" href="#">3</a>
                                </li>
                                <li role="presentation" class="divider"></li>
                                <li role="presentation"><a role="menuitem" tabindex="-1" href="#">4</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="col-md-3">
                    <div class="dropdown">
                        <div class="btn-group" id="fourthId">
                            <button class="btn btn-default dropdown-toggle disabled" type="button"
                                    data-toggle="dropdown">
                                Products
                                <span class="caret"></span></button>
                            <ul class="dropdown-menu" role="menu" aria-labelledby="menu1">
                                <li role="presentation"><a role="menuitem" tabindex="-1" href="#">1</a></li>
                                <li role="presentation"><a role="menuitem" tabindex="-1" href="#">2</a></li>
                                <li role="presentation"><a role="menuitem" tabindex="-1" href="#">3</a>
                                </li>
                                <li role="presentation" class="divider"></li>
                                <li role="presentation"><a role="menuitem" tabindex="-1" href="#">4</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>

Upvotes: 0

Views: 106

Answers (1)

Nadeemmnn Mohd
Nadeemmnn Mohd

Reputation: 724

JQUERY

 $('#firstId ul.dropdown-menu li').on('click',function(){
    $('.btn.btn-default.dropdown-toggle.disabled').removeClass('disabled');
    });

on firstId select find all classes with disabled and remove class disabled

JSFIDDLE DEMO

Upvotes: 1

Related Questions