6

I used bootstrap in my main menu and since my project has a lot of pages, subpages and sub-subpages I used the bootstrap dropdownmenu to navigate through this.

My client now wants to be able to go to the link associated with the dropdown-button itself too, rather than the childen. My client has text on a page called 'customer support', and text on subpages (children). Ideally I want the user to first click a dropdownmenu button (ex. "Customer service"), and a dropdownmenu opens up (which Bootstrap does), and on a second click be able to go to the link associated with that dropdownmenu button (ex. "/customer-service").

I'll share some code to make it a bit more understandable:

<body>
<nav class="navbar navbar-default">
    <div class="container-fluid">
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav">
                <li class="dropdown"> <a href="/customer-service" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Dropdown <span class="caret"></span></a>

                    <!-- click this menu-button once, and the submenu below opens, click this menu-button twice and you go to /customer-service -->
                    <ul class="dropdown-menu" role="menu">
                        <li><a href="#">Action</a>
                        </li>
                        <li><a href="#">Another action</a>
                        </li>
                        <li><a href="#">Something else here</a>
                        </li>
                        <li class="divider"></li>
                        <li><a href="#">Separated link</a>
                        </li>
                    </ul>
                </li>
            </ul>
            <ul class="nav navbar-nav">
                <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Dropdown <span class="caret"></span></a>

                    <ul class="dropdown-menu" role="menu">
                        <li><a href="#">Action</a>
                        </li>
                        <li><a href="#">Another action</a>
                        </li>
                        <li><a href="#">Something else here</a>
                        </li>
                        <li class="divider"></li>
                        <li><a href="#">Separated link</a>
                        </li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
</nav>

http://jsfiddle.net/kozog9rx/2/

(be sure to read the comment in the HTML and give the "Result-view" enough space/width so the menu appears)

4
  • 2
    Please share some code, it'll be easier to understand your problem and more expressive that way, than writing about it :) Commented Jan 11, 2015 at 17:06
  • I will thank you, sorry for my absense for a few days. I was quite busy with another project :) Commented Jan 13, 2015 at 22:29
  • I have changed the title and text of my post to make it more clear. Can you or someone else please have another look at it? Commented Jan 18, 2015 at 21:02
  • Just leaving this for anyone who comes in via Google : there's another question about this here : stackoverflow.com/questions/24247970/… with an answer that worked for me. Commented Nov 5, 2015 at 10:34

1 Answer 1

4

Well, assuming you are using bootstrap 3.2.0 Here's the code:

<li class="dropdown">
   <a href="example.com/page">Dropdown</a>
   <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>    
   <ul class="dropdown-menu" role="menu">
      <li><a href="#">Action</a></li>
      <li><a href="#">Another action</a></li>
      <li><a href="#">Something else here</a></li>
      <li class="divider"></li>
      <li><a href="#">Separated link</a></li>
      <li class="divider"></li>
      <li><a href="#">One more separated link</a></li>
   </ul>
</li>

What i'm doing is making the carat open the menu, and the text href to wherever you want it to go to.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your example. I tried it, but it does not quite give the result i was hoping for, because when i run it in my dev. enviroment the users has to click the arrow/caret seperatly to go to the link, and the text "Dropdown" to open the dropdownmenu. I want the user to open the dropdownmenu on the first click on the button, and to go to the link when the user clicks the same menubutton a second time. I believe this can be achieved through JS, but since this is very deep-level Bootstrap and JS i do not have a clue on where to begin.

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.