"close toggle when click outside"
Bootstrap 4.1.1 Snippet by naimansari

<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"> <div class="click">click me</div> <div class="showup">something I want to show</div> </div> </div>
body{margin:50px;} .showup{width:100px;height:100px; background:red; display:none;} .click{cursor:pointer;}
$(document).ready(function(){ $('.click').click(function(event){ event.stopPropagation(); $(".showup").slideToggle("fast"); }); $(".showup").on("click", function (event) { event.stopPropagation(); }); }); $(document).on("click", function () { $(".showup").hide(); });

Related: See More


Questions / Comments: