"slideToggle only clicked element"
Bootstrap 4.1.1 Snippet by naimansari

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<div class="container">
<div class="row">
<ul>
<li><a href="#">First</a></li>
<li class="has-submenu"><a class="link" href="#">Second</a>
<ul class="submenu">
<li><a href="#">submenu 1</a></li>
<li><a href="#">submenu 1</a></li>
</ul>
</li>
<li><a href="#">Third</a></li>
<li class="has-submenu"><a class="link" href="#">Fourth</a>
<ul class="submenu">
<li><a href="#">submenu 2</a></li>
<li><a href="#">submenu 2</a></li>
</ul>
</li>
</ul>
</div>
</div>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
3
4
5
6
7
8
9
10
11
12
13
ul {
list-style:none;
}
ul li {
width:200px;
background-color: #3f3f3f;
margin-bottom:1px;
}
ul li a {color:#fff;padding:3px 0px 3px 10px; disbplay:block; text-decoration:none;}
ul li.has-submenu ul {
display:none;
}
.submenu li {width:100px;}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
3
4
5
6
// Toggle
jQuery(document).ready(function(){
$('li.has-submenu a.link').click(function() {
$(this).next('.submenu').slideToggle(500);
});
});
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Related: See More


Questions / Comments: