Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap Twitter Dropdown: Make the parent follow the link

I have this bootstrap twitter dropdown menu. I replaced the click event with hover event. Now the only problem is is supposed to follow www.google.com but it doesn't. I tried with:

 jQuery(".nav .dropdown-toggle").click(function () {
      return true;
    });

but no dice.

Here is the code:

<html>
  <head>
    <title>text</title>
    <link type="text/css" rel="stylesheet"  href="docs/assets/css/bootstrap.css"/>
    <link type="text/css" rel="stylesheet"  href="docs/assets/css/bootstrap-responsive.css"/>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script type="text/javascript" src="js/bootstrap-dropdown.js"></script>
    <script type="text/javascript">
      $(function(){
        jQuery('.dropdown-toggle').dropdown();
        jQuery('ul.nav li.dropdown').hover(
        function() {jQuery(this).find('.dropdown-menu').stop(true, true).delay(200).fadeIn();},
        function() {jQuery(this).find('.dropdown-menu').stop(true, true).delay(200).fadeOut();}
      );

        jQuery(".nav .dropdown-toggle").click(function () {
          return true;
        });
      });
    </script>

  </head>
  <body>
    <ul class="nav nav-pills">
      <li class="dropdown">
        <a class="dropdown-toggle" data-toggle="dropdown" data-target="#" href="http://www.google.com">
          Dropdown
          <b class="caret"></b>
        </a>
        <ul class="dropdown-menu">
          <li><a href="#">text</a></li>
          <li><a href="#">text</a></li>
        </ul>
      </li>
    </ul>

  </body>
</html>

http://jsfiddle.net/rgdwM/

like image 307
Faraderegele Avatar asked Aug 03 '12 12:08

Faraderegele


2 Answers

You can accomplish this with no JavaScript by changing the markup a bit and adding a CSS class.

Change the HTML markup to (**note disabled is added next to dropdown-toggle):**

<a class="dropdown-toggle disabled" data-toggle="dropdown" data-target="#" href="http://www.google.com">
    Dropdown
    <b class="caret"></b>
</a>

If you want the submenu to appear on hover (since clicking will now go to the specified url), add this CSS class:

.nav li.dropdown:hover .dropdown-menu
{
    display: block;    
}

This applies to Bootstrap version 2.3.1.

like image 104
IntricatePixels Avatar answered Sep 21 '22 07:09

IntricatePixels


Not really too sure on what you are trying to achieve here.

But this would make the .click() take you to google.

$(".nav .dropdown-toggle").click(function () {
  window.location = "http://www.google.com";
});

As for why the <a> click event is eaten I am not currently sure.

like image 21
Sphvn Avatar answered Sep 24 '22 07:09

Sphvn