J
J
Jackie132016-04-14 21:51:49
JavaScript
Jackie13, 2016-04-14 21:51:49

How to make a dropdown menu on click on an icon in Bootstrap?

In the mobile version of Bootstrap, the submenu opens and closes by clicking on the parent.
What needs to be done so that the menu opens on a click on the icon, and the parent element is clickable.

<div class="collapse navbar-collapse navbar-ex1-collapse">
 <ul class="nav navbar-nav">
  <li class="dropdown">
  <a class="dropdown-toggle" data-toggle="dropdown" aria-expanded="true" href="parentlink"><span class="caret"></span></a>
  <div class="dropdown-menu">
     <ul>
       <li><a href="link1"></a></li>
       <li><a href="link2"></a></li>
       <li><a href="link3"></a></li>
    </ul>
  </div>
 </ul>
</div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
usica, 2016-05-16
@usica

<ul class="nav navbar-nav">
 <li class='fake'><a href='parentlink'>Ссылка</a></li>
  <li class="dropdown">
 <a class="dropdown-toggle" data-toggle="dropdown" aria-expanded="true" href="parentlink">Ссылка<span class="caret"></span></a>
...
</li>

 <li class='fake'><a href='parentlink2'>Ссылка2</a></li>
  <li class="dropdown">
 <a class="dropdown-toggle" data-toggle="dropdown" aria-expanded="true" href="parentlink2">Ссылка2<span class="caret"></span></a>
...
</li>

Make the fake class so that it is on top of the next li class="dropdown", but not its caret.
Then, when clicking on the text of the link, the link will be followed, when clicking on the caret, the child menu will open.
it is better to add via JS, then at the development stage there will be no problems with duplicating links.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question